Example #1
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            try
            {
                //create the resourcelocator object
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri);

                //create the session object
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);

                string rootNode  = helper.GetRootNodeName(helper.WSManOp, m_resource.ResourceUri, action);
                string input     = helper.ProcessInput(m_wsmanObject, filepath, helper.WSManOp, rootNode, valueset, m_resource, m_session);
                string resultXml = m_session.Invoke(action, m_resource, input, 0);

                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(resultXml);
                WriteObject(xmldoc.DocumentElement);
            }
            finally
            {
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (m_session != null)
                {
                    Dispose(m_session);
                }
            }
        }//End ProcessRecord()
Example #2
0
        protected override void ProcessRecord()
        {
            WSManHelper   wSManHelper  = new WSManHelper(this);
            IWSManEx      wSManClass   = (IWSManEx)(new WSManClass());
            string        str          = wSManHelper.CreateConnectionString(null, this.port, this.computername, this.applicationname);
            IWSManSession wSManSession = null;

            try
            {
                try
                {
                    wSManSession = wSManHelper.CreateSessionObject(wSManClass, this.Authentication, null, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(wSManSession.Identify(0));
                    base.WriteObject(xmlDocument.DocumentElement);
                }
                catch (Exception exception1)
                {
                    try
                    {
                        if (!string.IsNullOrEmpty(wSManSession.Error))
                        {
                            XmlDocument xmlDocument1 = new XmlDocument();
                            xmlDocument1.LoadXml(wSManSession.Error);
                            InvalidOperationException invalidOperationException = new InvalidOperationException(xmlDocument1.OuterXml);
                            ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, "WsManError", ErrorCategory.InvalidOperation, this.computername);
                            base.WriteError(errorRecord);
                        }
                    }
                    catch (Exception exception)
                    {
                    }
                }
            }
            finally
            {
                if (wSManSession != null)
                {
                    this.Dispose(wSManSession);
                }
            }
        }
Example #3
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            WSManHelper helper        = new WSManHelper(this);
            IWSManEx    wsmanObject   = (IWSManEx) new WSManClass();
            string      connectionStr = string.Empty;

            connectionStr = helper.CreateConnectionString(null, port, computername, applicationname);
            IWSManSession m_SessionObj = null;

            try
            {
                m_SessionObj         = helper.CreateSessionObject(wsmanObject, Authentication, null, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                m_SessionObj.Timeout = 1000; //1 sec. we are putting this low so that Test-WSMan can return promptly if the server goes unresponsive.
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(m_SessionObj.Identify(0));
                WriteObject(xmldoc.DocumentElement);
            }
            catch (Exception)
            {
                try
                {
                    if (!string.IsNullOrEmpty(m_SessionObj.Error))
                    {
                        XmlDocument ErrorDoc = new XmlDocument();
                        ErrorDoc.LoadXml(m_SessionObj.Error);
                        InvalidOperationException ex = new InvalidOperationException(ErrorDoc.OuterXml);
                        ErrorRecord er = new ErrorRecord(ex, "WsManError", ErrorCategory.InvalidOperation, computername);
                        this.WriteError(er);
                    }
                }
                catch (Exception)
                {}
            }
            finally
            {
                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }//End BeginProcessing()
		protected override void ProcessRecord()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManEx wSManClass = (IWSManEx)(new WSManClass());
			wSManHelper.WSManOp = "remove";
			IWSManSession wSManSession = null;
			try
			{
				string str = wSManHelper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
				if (this.connectionuri != null)
				{
					try
					{
						string[] strArrays = new string[1];
						object[] objArray = new object[4];
						objArray[0] = ":";
						objArray[1] = this.port;
						objArray[2] = "/";
						objArray[3] = this.applicationname;
						strArrays[0] = string.Concat(objArray);
						string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
						string[] strArrays2 = new string[1];
						strArrays2[0] = "//";
						string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
						this.computername = strArrays3[1].Trim();
					}
					catch (IndexOutOfRangeException indexOutOfRangeException)
					{
						wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
					}
				}
				wSManHelper.InitializeResourceLocator(this.optionset, this.selectorset, null, null, wSManClass, this.resourceuri);
				wSManSession = wSManHelper.CreateSessionObject(wSManClass, this.Authentication, this.sessionoption, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
				string uRIWithFilter = wSManHelper.GetURIWithFilter(this.resourceuri.ToString(), null, this.selectorset, wSManHelper.WSManOp);
				try
				{
					wSManSession.Delete(uRIWithFilter, 0);
				}
				catch (Exception exception1)
				{
					Exception exception = exception1;
					wSManHelper.AssertError(exception.Message, false, this.computername);
				}
			}
			finally
			{
				if (!string.IsNullOrEmpty(wSManSession.Error))
				{
					wSManHelper.AssertError(wSManSession.Error, true, this.resourceuri);
				}
				if (!string.IsNullOrEmpty(wSManClass.Error))
				{
					wSManHelper.AssertError(wSManClass.Error, true, this.resourceuri);
				}
				if (wSManSession != null)
				{
					this.Dispose(wSManSession);
				}
			}
		}
Example #5
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {

            WSManHelper helper = new WSManHelper(this);
            IWSManEx wsmanObject = (IWSManEx)new WSManClass();
            string connectionStr = String.Empty;
            connectionStr = helper.CreateConnectionString(null, port, computername, applicationname);
            IWSManSession m_SessionObj = null;
            try
            {
                m_SessionObj = helper.CreateSessionObject(wsmanObject, Authentication, null, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                m_SessionObj.Timeout = 1000; //1 sec. we are putting this low so that Test-WSMan can return promptly if the server goes unresponsive. 
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.LoadXml(m_SessionObj.Identify(0));
                WriteObject(xmldoc.DocumentElement);
            }
            catch(Exception)
            {
                try
                {
                    if (!String.IsNullOrEmpty(m_SessionObj.Error))
                    {
                        XmlDocument ErrorDoc = new XmlDocument();
                        ErrorDoc.LoadXml(m_SessionObj.Error);
                        InvalidOperationException ex = new InvalidOperationException(ErrorDoc.OuterXml);
                        ErrorRecord er = new ErrorRecord(ex, "WsManError", ErrorCategory.InvalidOperation, computername);
                        this.WriteError(er);
                    }
                }
                catch(Exception)
                {}
            }
            finally
            {
                if (m_SessionObj != null)
                    Dispose(m_SessionObj);
            }
        }//End BeginProcessing()
Example #6
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            IWSManEx m_wsmanObject = (IWSManEx)new WSManClass();
            helper = new WSManHelper(this);
            helper.WSManOp = "set";
            IWSManSession m_session = null;


            if (dialect != null)
            {
                if (dialect.ToString().Equals(helper.ALIAS_WQL, StringComparison.CurrentCultureIgnoreCase))
                    dialect = new Uri(helper.URI_WQL_DIALECT);
                if (dialect.ToString().Equals(helper.ALIAS_SELECTOR, StringComparison.CurrentCultureIgnoreCase))
                    dialect = new Uri(helper.URI_SELECTOR_DIALECT);
                if (dialect.ToString().Equals(helper.ALIAS_ASSOCIATION, StringComparison.CurrentCultureIgnoreCase))
                    dialect = new Uri(helper.URI_ASSOCIATION_DIALECT);
            }

            try
            {
                string connectionStr = String.Empty;
                connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
                if (connectionuri != null)
                {
                    try
                    {
                        //in the format http(s)://server[:port/applicationname]
                        string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                        string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                        computername = constrsplit1[1].Trim();
                    }
                    catch (IndexOutOfRangeException)
                    {
                        helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                    }

                }
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri);
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                string rootNode = helper.GetRootNodeName(helper.WSManOp, m_resource.ResourceUri, null);
                string input = helper.ProcessInput(m_wsmanObject, filepath, helper.WSManOp, rootNode, valueset, m_resource, m_session);

                XmlDocument xmldoc = new XmlDocument();
                try
                {
                    xmldoc.LoadXml(m_session.Put(m_resource, input, 0));
                }
                catch(XmlException ex)
                {
                    helper.AssertError(ex.Message, false, computername);
                }

                if (!string.IsNullOrEmpty(fragment))
                {
                    if (xmldoc.DocumentElement.ChildNodes.Count > 0)
                    {
                        foreach (XmlNode node in xmldoc.DocumentElement.ChildNodes)
                        {
                            if (node.Name.Equals(fragment, StringComparison.CurrentCultureIgnoreCase))
                                WriteObject(node.Name + " = " + node.InnerText);
                        }
                    }
                }
                else
                    WriteObject(xmldoc.DocumentElement);

            }
            finally
            {
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (m_session != null)
                    Dispose(m_session);
            }
        }//End ProcessRecord()
Example #7
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            IWSManSession m_session = null;
            IWSManEx m_wsmanObject = (IWSManEx)new WSManClass();
            helper = new WSManHelper(this);
            helper.WSManOp = "Get";
            string connectionStr = null;
            connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
            if (connectionuri != null)
            {
                try
                {
                    //in the format http(s)://server[:port/applicationname]
                    string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                    string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                    computername = constrsplit1[1].Trim();
                }
                catch (IndexOutOfRangeException)
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                }

            }
            try
            {
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, fragment, dialect, m_wsmanObject, resourceuri);
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);

                if (!enumerate)
                {
                    XmlDocument xmldoc = new XmlDocument();
                    try
                    {
                        xmldoc.LoadXml(m_session.Get(m_resource, 0));
                    }
                    catch(XmlException ex)
                    {
                        helper.AssertError(ex.Message, false, computername);
                    }

                    if (!string.IsNullOrEmpty(fragment))
                    {
                        WriteObject(xmldoc.FirstChild.LocalName + "=" + xmldoc.FirstChild.InnerText);
                    }
                    else
                    {
                        WriteObject(xmldoc.FirstChild);
                    }
                }
                else
                {
                    try
                    {
                        ReturnEnumeration(m_wsmanObject, m_resource, m_session);
                    }
                    catch (Exception ex)
                    {
                        helper.AssertError(ex.Message, false, computername);
                    }
                }

            }
            finally
            {
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (m_session != null)
                    Dispose(m_session);
            }
        }
Example #8
0
        /// <summary>
        /// ProcessRecord method.
        /// </summary>
        protected override void ProcessRecord()
        {
            WSManHelper helper = new WSManHelper(this);
            IWSManEx m_wsmanObject = (IWSManEx)new WSManClass();
            helper.WSManOp = "remove";
            IWSManSession m_session = null;
            try
            {
                string connectionStr = String.Empty;
                connectionStr = helper.CreateConnectionString(connectionuri, port, computername, applicationname);
                if (connectionuri != null)
                {
                    try
                    {
                        //in the format http(s)://server[:port/applicationname]
                        string[] constrsplit = connectionuri.OriginalString.Split(new string[] { ":" + port + "/" + applicationname }, StringSplitOptions.None);
                        string[] constrsplit1 = constrsplit[0].Split(new string[] { "//" }, StringSplitOptions.None);
                        computername = constrsplit1[1].Trim();
                    }
                    catch (IndexOutOfRangeException)
                    {
                        helper.AssertError(helper.GetResourceMsgFromResourcetext("NotProperURI"), false, connectionuri);
                    }

                }
                IWSManResourceLocator m_resource = helper.InitializeResourceLocator(optionset, selectorset, null, null, m_wsmanObject, resourceuri);
                m_session = helper.CreateSessionObject(m_wsmanObject, Authentication, sessionoption, Credential, connectionStr, CertificateThumbprint, usessl.IsPresent);
                string ResourceURI = helper.GetURIWithFilter(resourceuri.ToString(), null, selectorset, helper.WSManOp);
                try
                {
                    ((IWSManSession)m_session).Delete(ResourceURI, 0);
                }
                catch (Exception ex)
                {
                    helper.AssertError(ex.Message, false, computername);
                }

            }
            finally
            {
                if (!String.IsNullOrEmpty(m_session.Error))
                {
                    helper.AssertError(m_session.Error, true, resourceuri);
                }
                if (!String.IsNullOrEmpty(m_wsmanObject.Error))
                {
                    helper.AssertError(m_wsmanObject.Error, true, resourceuri);
                }
                if (m_session != null)
                    Dispose(m_session);

            }

        }//End ProcessRecord()
Example #9
0
		protected override void ProcessRecord()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManEx wSManClass = (IWSManEx)(new WSManClass());
			string str = wSManHelper.CreateConnectionString(null, this.port, this.computername, this.applicationname);
			IWSManSession wSManSession = null;
			try
			{
				try
				{
					wSManSession = wSManHelper.CreateSessionObject(wSManClass, this.Authentication, null, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
					XmlDocument xmlDocument = new XmlDocument();
					xmlDocument.LoadXml(wSManSession.Identify(0));
					base.WriteObject(xmlDocument.DocumentElement);
				}
				catch (Exception exception1)
				{
					try
					{
						if (!string.IsNullOrEmpty(wSManSession.Error))
						{
							XmlDocument xmlDocument1 = new XmlDocument();
							xmlDocument1.LoadXml(wSManSession.Error);
							InvalidOperationException invalidOperationException = new InvalidOperationException(xmlDocument1.OuterXml);
							ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, "WsManError", ErrorCategory.InvalidOperation, this.computername);
							base.WriteError(errorRecord);
						}
					}
					catch (Exception exception)
					{
					}
				}
			}
			finally
			{
				if (wSManSession != null)
				{
					this.Dispose(wSManSession);
				}
			}
		}
Example #10
0
        protected override void ProcessRecord()
        {
            WSManHelper wSManHelper = new WSManHelper(this);
            IWSManEx    wSManClass  = (IWSManEx)(new WSManClass());

            wSManHelper.WSManOp = "remove";
            IWSManSession wSManSession = null;

            try
            {
                string str = wSManHelper.CreateConnectionString(this.connectionuri, this.port, this.computername, this.applicationname);
                if (this.connectionuri != null)
                {
                    try
                    {
                        string[] strArrays = new string[1];
                        object[] objArray  = new object[4];
                        objArray[0]  = ":";
                        objArray[1]  = this.port;
                        objArray[2]  = "/";
                        objArray[3]  = this.applicationname;
                        strArrays[0] = string.Concat(objArray);
                        string[] strArrays1 = this.connectionuri.OriginalString.Split(strArrays, StringSplitOptions.None);
                        string[] strArrays2 = new string[1];
                        strArrays2[0] = "//";
                        string[] strArrays3 = strArrays1[0].Split(strArrays2, StringSplitOptions.None);
                        this.computername = strArrays3[1].Trim();
                    }
                    catch (IndexOutOfRangeException indexOutOfRangeException)
                    {
                        wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("NotProperURI"), false, this.connectionuri);
                    }
                }
                wSManHelper.InitializeResourceLocator(this.optionset, this.selectorset, null, null, wSManClass, this.resourceuri);
                wSManSession = wSManHelper.CreateSessionObject(wSManClass, this.Authentication, this.sessionoption, this.Credential, str, this.CertificateThumbprint, this.usessl.IsPresent);
                string uRIWithFilter = wSManHelper.GetURIWithFilter(this.resourceuri.ToString(), null, this.selectorset, wSManHelper.WSManOp);
                try
                {
                    wSManSession.Delete(uRIWithFilter, 0);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    wSManHelper.AssertError(exception.Message, false, this.computername);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(wSManSession.Error))
                {
                    wSManHelper.AssertError(wSManSession.Error, true, this.resourceuri);
                }
                if (!string.IsNullOrEmpty(wSManClass.Error))
                {
                    wSManHelper.AssertError(wSManClass.Error, true, this.resourceuri);
                }
                if (wSManSession != null)
                {
                    this.Dispose(wSManSession);
                }
            }
        }