Exemple #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()
Exemple #2
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            WSManHelper helper = new WSManHelper(this);

            if (computername == null)
            {
                computername = "localhost";
            }

            if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(WSManStringLiterals.rootpath + ":" + WSManStringLiterals.DefaultPathSeparator + computername, StringComparison.OrdinalIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("DisconnectFailure"), false, computername);
            }

            if (computername.Equals("localhost", StringComparison.OrdinalIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("LocalHost"), false, computername);
            }

            object _ws = helper.RemoveFromDictionary(computername);

            if (_ws != null)
            {
                Dispose(_ws);
            }
            else
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, computername);
            }
        }
Exemple #3
0
        protected override void BeginProcessing()
        {
            WSManHelper wSManHelper = new WSManHelper(this);

            if (this.computername == null)
            {
                this.computername = "localhost";
            }
            if (base.SessionState.Path.CurrentProviderLocation("WSMan").Path.StartsWith(string.Concat("WSMan:", (char)92, this.computername), StringComparison.CurrentCultureIgnoreCase))
            {
                wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisconnectFailure"), false, this.computername);
            }
            if (this.computername.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
            {
                wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("LocalHost"), false, this.computername);
            }
            object obj = wSManHelper.RemoveFromDictionary(this.computername);

            if (obj == null)
            {
                wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, this.computername);
                return;
            }
            else
            {
                this.Dispose(obj);
                return;
            }
        }
Exemple #4
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            WSManHelper helper = new WSManHelper(this);

            if (connectionuri != null)
            {
                try
                {
                    // always in the format http://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);
                }
            }

            string crtComputerName = computername;

            if (crtComputerName == null)
            {
                crtComputerName = "localhost";
            }

            if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(this.SessionState.Drive.Current.Name + ":" + WSManStringLiterals.DefaultPathSeparator + crtComputerName, StringComparison.OrdinalIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("ConnectFailure"), false, computername);
            }

            helper.CreateWsManConnection(ParameterSetName, connectionuri, port, computername, applicationname, usessl.IsPresent, Authentication, sessionoption, Credential, CertificateThumbprint);
        }
		protected override void BeginProcessing()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			if (this.computername == null)
			{
				this.computername = "localhost";
			}
			if (base.SessionState.Path.CurrentProviderLocation("WSMan").Path.StartsWith(string.Concat("WSMan:", (char)92, this.computername), StringComparison.CurrentCultureIgnoreCase))
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisconnectFailure"), false, this.computername);
			}
			if (this.computername.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("LocalHost"), false, this.computername);
			}
			object obj = wSManHelper.RemoveFromDictionary(this.computername);
			if (obj == null)
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, this.computername);
				return;
			}
			else
			{
				this.Dispose(obj);
				return;
			}
		}
        protected override void BeginProcessing()
        {
            WSManHelper wSManHelper = new WSManHelper(this);

            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);
                }
            }
            string str = this.computername;

            if (str == null)
            {
                str = "localhost";
            }
            object[] name = new object[4];
            name[0] = base.SessionState.Drive.Current.Name;
            name[1] = ":";
            name[2] = (char)92;
            name[3] = str;
            if (base.SessionState.Path.CurrentProviderLocation("WSMan").Path.StartsWith(string.Concat(name), StringComparison.CurrentCultureIgnoreCase))
            {
                wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("ConnectFailure"), false, this.computername);
            }
            wSManHelper.CreateWsManConnection(base.ParameterSetName, this.connectionuri, this.port, this.computername, this.applicationname, this.usessl.IsPresent, this.Authentication, this.sessionoption, this.Credential, this.CertificateThumbprint);
        }
Exemple #7
0
        private void DisableServerSideSettings()
        {
            WSManHelper   helper       = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();

            if (m_SessionObj == null)
            {
                return;
            }

            try
            {
                string      result      = m_SessionObj.Get(helper.Service_CredSSP_Uri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string      inputXml    = null;
                resultopxml.LoadXml(result);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.Service_CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode == null))
                {
                    inputXml = string.Format(CultureInfo.InvariantCulture,
                                             @"<cfg:Auth xmlns:cfg=""{0}""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>",
                                             helper.Service_CredSSP_XMLNmsp);
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex,
                                                     helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"),
                                                     ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                m_SessionObj.Put(helper.Service_CredSSP_Uri, inputXml, 0);
            }
            finally
            {
                if (!string.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
Exemple #8
0
        private void DisableClientSideSettings()
        {
            WSManHelper   helper       = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();

            if (m_SessionObj is null)
            {
                return;
            }

            try
            {
                string      result      = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string      inputXml    = null;
                resultopxml.LoadXml(result);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode is null))
                {
                    inputXml = @"<cfg:Auth xmlns:cfg=""http://schemas.microsoft.com/wbem/wsman/1/config/client/auth""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                m_SessionObj.Put(helper.CredSSP_RUri, inputXml, 0);

                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    this.DeleteUserDelegateSettings();
                }
                else
                {
                    ThreadStart start  = new ThreadStart(this.DeleteUserDelegateSettings);
                    Thread      thread = new Thread(start);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }

                if (!helper.ValidateCreadSSPRegistryRetry(false, null, applicationname))
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
                }
            }
        private void DisableServerSideSettings()
        {
            WSManHelper   wSManHelper  = new WSManHelper(this);
            IWSManSession wSManSession = base.CreateWSManSession();

            if (wSManSession != null)
            {
                try
                {
                    string      str         = wSManSession.Get(wSManHelper.Service_CredSSP_Uri, 0);
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(str);
                    XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
                    xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.Service_CredSSP_XMLNmsp);
                    XmlNode xmlNodes = xmlDocument.SelectSingleNode(wSManHelper.CredSSP_SNode, xmlNamespaceManagers);
                    if (xmlNodes == null)
                    {
                        InvalidOperationException invalidOperationException = new InvalidOperationException();
                        ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, wSManHelper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                        base.WriteError(errorRecord);
                    }
                    else
                    {
                        object[] serviceCredSSPXMLNmsp = new object[1];
                        serviceCredSSPXMLNmsp[0] = wSManHelper.Service_CredSSP_XMLNmsp;
                        string str1 = string.Format(CultureInfo.InvariantCulture, "<cfg:Auth xmlns:cfg=\"{0}\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>", serviceCredSSPXMLNmsp);
                        wSManSession.Put(wSManHelper.Service_CredSSP_Uri, str1, 0);
                    }
                }
                finally
                {
                    if (!string.IsNullOrEmpty(wSManSession.Error))
                    {
                        wSManHelper.AssertError(wSManSession.Error, true, null);
                    }
                    if (wSManSession != null)
                    {
                        this.Dispose(wSManSession);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
Exemple #10
0
        private void DisableClientSideSettings()
        {
            WSManHelper helper = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();
            if (null == m_SessionObj)
            {
                return;
            }

            try
            {
                string result = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string inputXml = null;
                resultopxml.LoadXml(result);
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode == null))
                {
                    inputXml = @"<cfg:Auth xmlns:cfg=""http://schemas.microsoft.com/wbem/wsman/1/config/client/auth""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }
                m_SessionObj.Put(helper.CredSSP_RUri, inputXml, 0);
               
#if !CORECLR
                if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                {
                    this.DeleteUserDelegateSettings();
                }
                else
                {
                    ThreadStart start = new ThreadStart(this.DeleteUserDelegateSettings);
                    Thread thread = new Thread(start);
                    thread.SetApartmentState(ApartmentState.STA);
                    thread.Start();
                    thread.Join();
                }
#else
                {
                    ThreadStart start = new ThreadStart(this.DeleteUserDelegateSettings);
                    Thread thread = new Thread(start);
                    thread.Start();
                    thread.Join();
                }
#endif

                if (!helper.ValidateCreadSSPRegistryRetry(false, null, applicationname))
                {
                    helper.AssertError(helper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
                }
            }
            catch (System.Xml.XPath.XPathException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "XpathException", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            finally
            {
                if (!String.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                    Dispose(m_SessionObj);
            }
        }
        private void DisableClientSideSettings()
        {
            WSManHelper   wSManHelper  = new WSManHelper(this);
            IWSManSession wSManSession = base.CreateWSManSession();

            if (wSManSession != null)
            {
                try
                {
                    try
                    {
                        string      str         = wSManSession.Get(wSManHelper.CredSSP_RUri, 0);
                        XmlDocument xmlDocument = new XmlDocument();
                        xmlDocument.LoadXml(str);
                        XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
                        xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.CredSSP_XMLNmsp);
                        XmlNode xmlNodes = xmlDocument.SelectSingleNode(wSManHelper.CredSSP_SNode, xmlNamespaceManagers);
                        if (xmlNodes == null)
                        {
                            InvalidOperationException invalidOperationException = new InvalidOperationException();
                            ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, wSManHelper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                            base.WriteError(errorRecord);
                            return;
                        }
                        else
                        {
                            string str1 = "<cfg:Auth xmlns:cfg=\"http://schemas.microsoft.com/wbem/wsman/1/config/client/auth\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
                            wSManSession.Put(wSManHelper.CredSSP_RUri, str1, 0);
                            if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
                            {
                                ThreadStart threadStart = new ThreadStart(this.DeleteUserDelegateSettings);
                                Thread      thread      = new Thread(threadStart);
                                thread.SetApartmentState(ApartmentState.STA);
                                thread.Start();
                                thread.Join();
                            }
                            else
                            {
                                this.DeleteUserDelegateSettings();
                            }
                            if (!wSManHelper.ValidateCreadSSPRegistryRetry(false, null, "wsman"))
                            {
                                wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
                            }
                        }
                    }
                    catch (XPathException xPathException1)
                    {
                        XPathException xPathException = xPathException1;
                        ErrorRecord    errorRecord1   = new ErrorRecord(xPathException, "XpathException", ErrorCategory.InvalidOperation, null);
                        base.WriteError(errorRecord1);
                    }
                }
                finally
                {
                    if (!string.IsNullOrEmpty(wSManSession.Error))
                    {
                        wSManHelper.AssertError(wSManSession.Error, true, null);
                    }
                    if (wSManSession != null)
                    {
                        this.Dispose(wSManSession);
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
		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);
				}
			}
		}
Exemple #13
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()
Exemple #14
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);
            }
        }
Exemple #15
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            helper = new WSManHelper(this );
            helper.WSManOp = "new";
            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);
                }

            }

        }//End BeginProcessing()
Exemple #16
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()
Exemple #17
0
		protected override void BeginProcessing()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			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);
				}
			}
			string str = this.computername;
			if (str == null)
			{
				str = "localhost";
			}
			object[] name = new object[4];
			name[0] = base.SessionState.Drive.Current.Name;
			name[1] = ":";
			name[2] = (char)92;
			name[3] = str;
			if (base.SessionState.Path.CurrentProviderLocation("WSMan").Path.StartsWith(string.Concat(name), StringComparison.CurrentCultureIgnoreCase))
			{
				wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("ConnectFailure"), false, this.computername);
			}
			wSManHelper.CreateWsManConnection(base.ParameterSetName, this.connectionuri, this.port, this.computername, this.applicationname, this.usessl.IsPresent, this.Authentication, this.sessionoption, this.Credential, this.CertificateThumbprint);
		}
Exemple #18
0
        private void DisableServerSideSettings()
        {
            WSManHelper helper = new WSManHelper(this);
            IWSManSession m_SessionObj = CreateWSManSession();
            if (null == m_SessionObj)
            {
                return;
            }

            try
            {
                string result = m_SessionObj.Get(helper.Service_CredSSP_Uri, 0);
                XmlDocument resultopxml = new XmlDocument();
                string inputXml = null;
                resultopxml.LoadXml(result);

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", helper.Service_CredSSP_XMLNmsp);
                XmlNode xNode = resultopxml.SelectSingleNode(helper.CredSSP_SNode, nsmgr);
                if (!(xNode == null))
                {
                    inputXml = string.Format(CultureInfo.InvariantCulture,
                        @"<cfg:Auth xmlns:cfg=""{0}""><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>",
                        helper.Service_CredSSP_XMLNmsp);
                }
                else
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, 
                        helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), 
                        ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                m_SessionObj.Put(helper.Service_CredSSP_Uri, inputXml, 0);
            }
            finally
            {
                if (!String.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
		private void DisableClientSideSettings()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManSession wSManSession = base.CreateWSManSession();
			if (wSManSession != null)
			{
				try
				{
					try
					{
						string str = wSManSession.Get(wSManHelper.CredSSP_RUri, 0);
						XmlDocument xmlDocument = new XmlDocument();
						xmlDocument.LoadXml(str);
						XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
						xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.CredSSP_XMLNmsp);
						XmlNode xmlNodes = xmlDocument.SelectSingleNode(wSManHelper.CredSSP_SNode, xmlNamespaceManagers);
						if (xmlNodes == null)
						{
							InvalidOperationException invalidOperationException = new InvalidOperationException();
							ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, wSManHelper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
							base.WriteError(errorRecord);
							return;
						}
						else
						{
							string str1 = "<cfg:Auth xmlns:cfg=\"http://schemas.microsoft.com/wbem/wsman/1/config/client/auth\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>";
							wSManSession.Put(wSManHelper.CredSSP_RUri, str1, 0);
							if (Thread.CurrentThread.GetApartmentState() != ApartmentState.STA)
							{
								ThreadStart threadStart = new ThreadStart(this.DeleteUserDelegateSettings);
								Thread thread = new Thread(threadStart);
								thread.SetApartmentState(ApartmentState.STA);
								thread.Start();
								thread.Join();
							}
							else
							{
								this.DeleteUserDelegateSettings();
							}
							if (!wSManHelper.ValidateCreadSSPRegistryRetry(false, null, "wsman"))
							{
								wSManHelper.AssertError(wSManHelper.GetResourceMsgFromResourcetext("DisableCredSSPPolicyValidateError"), false, null);
							}
						}
					}
					catch (XPathException xPathException1)
					{
						XPathException xPathException = xPathException1;
						ErrorRecord errorRecord1 = new ErrorRecord(xPathException, "XpathException", ErrorCategory.InvalidOperation, null);
						base.WriteError(errorRecord1);
					}
				}
				finally
				{
					if (!string.IsNullOrEmpty(wSManSession.Error))
					{
						wSManHelper.AssertError(wSManSession.Error, true, null);
					}
					if (wSManSession != null)
					{
						this.Dispose(wSManSession);
					}
				}
				return;
			}
			else
			{
				return;
			}
		}
Exemple #20
0
        /// <summary>
        /// Method to begin processing.
        /// </summary>
        protected override void BeginProcessing()
        {
            // If not running elevated, then throw an "elevation required" error message.
            WSManHelper.ThrowIfNotAdministrator();
            helper = new WSManHelper(this);
            IWSManSession m_SessionObj = null;

            try
            {
                IWSManEx wsmanObject = (IWSManEx) new WSManClass();
                m_SessionObj = (IWSManSession)wsmanObject.CreateSession(null, 0, null);
                string  result = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlNode node   = helper.GetXmlNode(result, helper.CredSSP_SNode, helper.CredSSP_XMLNmsp);
                if (node == null)
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }
                // The application name MUST be "wsman" as wsman got approval from security
                // folks who suggested to register the SPN with name "wsman".
                const string applicationname = "wsman";
                string       credsspResult   = GetDelegateSettings(applicationname);
                if (string.IsNullOrEmpty(credsspResult))
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("NoDelegateFreshCred"));
                }
                else
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("DelegateFreshCred") + credsspResult);
                }

                // Get the server side settings
                result = m_SessionObj.Get(helper.Service_CredSSP_Uri, 0);
                node   = helper.GetXmlNode(result, helper.CredSSP_SNode, helper.Service_CredSSP_XMLNmsp);
                if (node == null)
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                if (node.InnerText.Equals("true", StringComparison.OrdinalIgnoreCase))
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("CredSSPServiceConfigured"));
                }
                else
                {
                    WriteObject(helper.GetResourceMsgFromResourcetext("CredSSPServiceNotConfigured"));
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "UnauthorizedAccess", ErrorCategory.PermissionDenied, null);
                WriteError(er);
            }
            catch (SecurityException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "SecurityException", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            catch (ArgumentException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "InvalidArgument", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            catch (System.Xml.XPath.XPathException ex)
            {
                ErrorRecord er = new ErrorRecord(ex, "XPathException", ErrorCategory.InvalidOperation, null);
                WriteError(er);
            }
            finally
            {
                if (!string.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
Exemple #21
0
        /// <summary>
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// </exception>
        private void EnableClientSideSettings()
        {
            string query   = helper.GetResourceMsgFromResourcetext("CredSSPContinueQuery");
            string caption = helper.GetResourceMsgFromResourcetext("CredSSPContinueCaption");

            if (!force && !ShouldContinue(query, caption))
            {
                return;
            }

            IWSManSession m_SessionObj = CreateWSManSession();

            if (m_SessionObj == null)
            {
                return;
            }

            try
            {
                // get the credssp node to check if wsman is configured on this machine
                string  result = m_SessionObj.Get(helper.CredSSP_RUri, 0);
                XmlNode node   = helper.GetXmlNode(result, helper.CredSSP_SNode, helper.CredSSP_XMLNmsp);

                if (node == null)
                {
                    InvalidOperationException ex = new InvalidOperationException();
                    ErrorRecord er = new ErrorRecord(ex, helper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                const string newxmlcontent = @"<cfg:Auth xmlns:cfg=""http://schemas.microsoft.com/wbem/wsman/1/config/client/auth""><cfg:CredSSP>true</cfg:CredSSP></cfg:Auth>";
                try
                {
                    XmlDocument xmldoc = new XmlDocument();
                    // push the xml string with credssp enabled
                    xmldoc.LoadXml(m_SessionObj.Put(helper.CredSSP_RUri, newxmlcontent, 0));

                    // set the Registry using GroupPolicyObject
                    if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
                    {
                        this.UpdateCurrentUserRegistrySettings();
                    }
                    else
                    {
                        ThreadStart start  = new ThreadStart(this.UpdateCurrentUserRegistrySettings);
                        Thread      thread = new Thread(start);
                        thread.SetApartmentState(ApartmentState.STA);
                        thread.Start();
                        thread.Join();
                    }

                    if (helper.ValidateCreadSSPRegistryRetry(true, delegatecomputer, applicationname))
                    {
                        WriteObject(xmldoc.FirstChild);
                    }
                    else
                    {
                        helper.AssertError(helper.GetResourceMsgFromResourcetext("EnableCredSSPPolicyValidateError"), false, delegatecomputer);
                    }
                }
                catch (COMException)
                {
                    helper.AssertError(m_SessionObj.Error, true, delegatecomputer);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, delegatecomputer);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
		private void DisableServerSideSettings()
		{
			WSManHelper wSManHelper = new WSManHelper(this);
			IWSManSession wSManSession = base.CreateWSManSession();
			if (wSManSession != null)
			{
				try
				{
					string str = wSManSession.Get(wSManHelper.Service_CredSSP_Uri, 0);
					XmlDocument xmlDocument = new XmlDocument();
					xmlDocument.LoadXml(str);
					XmlNamespaceManager xmlNamespaceManagers = new XmlNamespaceManager(xmlDocument.NameTable);
					xmlNamespaceManagers.AddNamespace("cfg", wSManHelper.Service_CredSSP_XMLNmsp);
					XmlNode xmlNodes = xmlDocument.SelectSingleNode(wSManHelper.CredSSP_SNode, xmlNamespaceManagers);
					if (xmlNodes == null)
					{
						InvalidOperationException invalidOperationException = new InvalidOperationException();
						ErrorRecord errorRecord = new ErrorRecord(invalidOperationException, wSManHelper.GetResourceMsgFromResourcetext("WinrmNotConfigured"), ErrorCategory.InvalidOperation, null);
						base.WriteError(errorRecord);
					}
					else
					{
						object[] serviceCredSSPXMLNmsp = new object[1];
						serviceCredSSPXMLNmsp[0] = wSManHelper.Service_CredSSP_XMLNmsp;
						string str1 = string.Format(CultureInfo.InvariantCulture, "<cfg:Auth xmlns:cfg=\"{0}\"><cfg:CredSSP>false</cfg:CredSSP></cfg:Auth>", serviceCredSSPXMLNmsp);
						wSManSession.Put(wSManHelper.Service_CredSSP_Uri, str1, 0);
					}
				}
				finally
				{
					if (!string.IsNullOrEmpty(wSManSession.Error))
					{
						wSManHelper.AssertError(wSManSession.Error, true, null);
					}
					if (wSManSession != null)
					{
						this.Dispose(wSManSession);
					}
				}
				return;
			}
			else
			{
				return;
			}
		}
        private void QuickConfigRemoting(bool serviceonly)
        {
            IWSManSession m_SessionObj = null;

            try
            {
                string   transport;
                IWSManEx wsmanObject = (IWSManEx) new WSManClass();
                m_SessionObj = (IWSManSession)wsmanObject.CreateSession(null, 0, null);
                string xpathEnabled     = string.Empty;
                string xpathText        = string.Empty;
                string xpathUpdate      = string.Empty;
                string analysisInputXml = string.Empty;
                string action           = string.Empty;
                string xpathStatus      = string.Empty;
                string xpathResult      = string.Empty;

                if (!usessl)
                {
                    transport = "http";
                }
                else
                {
                    transport = "https";
                }

                if (serviceonly)
                {
                    analysisInputXml = @"<AnalyzeService_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""></AnalyzeService_INPUT>";
                    action           = "AnalyzeService";
                }
                else
                {
                    string openAllProfiles = skipNetworkProfileCheck ? "<Force/>" : string.Empty;
                    analysisInputXml = @"<Analyze_INPUT xmlns=""http://schemas.microsoft.com/wbem/wsman/1/config/service""><Transport>" + transport + "</Transport>" + openAllProfiles + "</Analyze_INPUT>";
                    action           = "Analyze";
                }

                string      analysisOutputXml = m_SessionObj.Invoke(action, "winrm/config/service", analysisInputXml, 0);
                XmlDocument resultopxml       = new XmlDocument();
                resultopxml.LoadXml(analysisOutputXml);

                if (serviceonly)
                {
                    xpathEnabled = "/cfg:AnalyzeService_OUTPUT/cfg:RemotingEnabled";
                    xpathText    = "/cfg:AnalyzeService_OUTPUT/cfg:Results";
                    xpathUpdate  = "/cfg:AnalyzeService_OUTPUT/cfg:EnableService_INPUT";
                }
                else
                {
                    xpathEnabled = "/cfg:Analyze_OUTPUT/cfg:RemotingEnabled";
                    xpathText    = "/cfg:Analyze_OUTPUT/cfg:Results";
                    xpathUpdate  = "/cfg:Analyze_OUTPUT/cfg:EnableRemoting_INPUT";
                }

                XmlNamespaceManager nsmgr = new XmlNamespaceManager(resultopxml.NameTable);
                nsmgr.AddNamespace("cfg", "http://schemas.microsoft.com/wbem/wsman/1/config/service");
                string  enabled         = resultopxml.SelectSingleNode(xpathEnabled, nsmgr).InnerText;
                XmlNode sourceAttribute = resultopxml.SelectSingleNode(xpathEnabled, nsmgr).Attributes.GetNamedItem("Source");
                string  source          = null;
                if (sourceAttribute != null)
                {
                    source = sourceAttribute.Value;
                }

                string rxml = string.Empty;
                if (enabled.Equals("true"))
                {
                    string Err_Msg = string.Empty;
                    if (serviceonly)
                    {
                        Err_Msg = WSManResourceLoader.GetResourceString("L_QuickConfigNoServiceChangesNeeded_Message");
                    }
                    else
                    {
                        Err_Msg = WSManResourceLoader.GetResourceString("L_QuickConfigNoChangesNeeded_Message");
                    }
                    //  ArgumentException e = new ArgumentException(Err_Msg);
                    // ErrorRecord er = new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                    //  WriteError(er);
                    WriteObject(Err_Msg);
                    return;
                }

                if (!enabled.Equals("false"))
                {
                    ArgumentException e  = new ArgumentException(WSManResourceLoader.GetResourceString("L_QuickConfig_InvalidBool_0_ErrorMessage"));
                    ErrorRecord       er = new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                string resultAction = resultopxml.SelectSingleNode(xpathText, nsmgr).InnerText;
                if (source != null && source.Equals("GPO"))
                {
                    string Info_Msg = WSManResourceLoader.GetResourceString("L_QuickConfig_RemotingDisabledbyGP_00_ErrorMessage");
                    Info_Msg += " " + resultAction;
                    ArgumentException e = new ArgumentException(Info_Msg);
                    WriteError(new ErrorRecord(e, "NotSpecified", ErrorCategory.NotSpecified, null));
                    return;
                }

                string inputXml = resultopxml.SelectSingleNode(xpathUpdate, nsmgr).OuterXml;
                if (resultAction.Equals(string.Empty) || inputXml.Equals(string.Empty))
                {
                    ArgumentException e  = new ArgumentException(WSManResourceLoader.GetResourceString("L_ERR_Message") + WSManResourceLoader.GetResourceString("L_QuickConfig_MissingUpdateXml_0_ErrorMessage"));
                    ErrorRecord       er = new ErrorRecord(e, "InvalidOperation", ErrorCategory.InvalidOperation, null);
                    WriteError(er);
                    return;
                }

                if (serviceonly)
                {
                    action = "EnableService";
                }
                else
                {
                    action = "EnableRemoting";
                }

                rxml = m_SessionObj.Invoke(action, "winrm/config/service", inputXml, 0);
                XmlDocument finalxml = new XmlDocument();
                finalxml.LoadXml(rxml);

                if (serviceonly)
                {
                    xpathStatus = "/cfg:EnableService_OUTPUT/cfg:Status";
                    xpathResult = "/cfg:EnableService_OUTPUT/cfg:Results";
                }
                else
                {
                    xpathStatus = "/cfg:EnableRemoting_OUTPUT/cfg:Status";
                    xpathResult = "/cfg:EnableRemoting_OUTPUT/cfg:Results";
                }

                if (finalxml.SelectSingleNode(xpathStatus, nsmgr).InnerText.ToString().Equals("succeeded"))
                {
                    if (serviceonly)
                    {
                        WriteObject(WSManResourceLoader.GetResourceString("L_QuickConfigUpdatedService_Message"));
                    }
                    else
                    {
                        WriteObject(WSManResourceLoader.GetResourceString("L_QuickConfigUpdated_Message"));
                    }

                    WriteObject(finalxml.SelectSingleNode(xpathResult, nsmgr).InnerText);
                }
                else
                {
                    helper.AssertError(WSManResourceLoader.GetResourceString("L_ERR_Message") + WSManResourceLoader.GetResourceString("L_QuickConfigUpdateFailed_ErrorMessage"), false, null);
                }
            }
            finally
            {
                if (!string.IsNullOrEmpty(m_SessionObj.Error))
                {
                    helper.AssertError(m_SessionObj.Error, true, null);
                }

                if (m_SessionObj != null)
                {
                    Dispose(m_SessionObj);
                }
            }
        }
Exemple #24
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {

            WSManHelper helper = new WSManHelper(this);
            if (connectionuri != null)
            {
                try
                {
                    //always in the format http://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);
                }
            }
            string crtComputerName = computername;
            if (crtComputerName == null)
            {
                crtComputerName = "localhost";
            }
            if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(this.SessionState.Drive.Current.Name + ":" + WSManStringLiterals.DefaultPathSeparator + crtComputerName, StringComparison.CurrentCultureIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("ConnectFailure"), false, computername);
            }
            helper.CreateWsManConnection(ParameterSetName, connectionuri, port, computername, applicationname, usessl.IsPresent, Authentication, sessionoption, Credential, CertificateThumbprint);
        }//End BeginProcessing()    
Exemple #25
0
        /// <summary>
        /// BeginProcessing method.
        /// </summary>
        protected override void BeginProcessing()
        {
            WSManHelper helper = new WSManHelper(this);
            if (computername == null)
            {
                computername = "localhost";
            }
            if (this.SessionState.Path.CurrentProviderLocation(WSManStringLiterals.rootpath).Path.StartsWith(WSManStringLiterals.rootpath + ":" + WSManStringLiterals.DefaultPathSeparator + computername, StringComparison.CurrentCultureIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("DisconnectFailure"), false, computername);
            }
            if (computername.Equals("localhost", StringComparison.CurrentCultureIgnoreCase))
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("LocalHost"), false, computername);
            }

            object _ws = helper.RemoveFromDictionary(computername);
            if (_ws != null)
            {
                Dispose(_ws);
            }
            else
            {
                helper.AssertError(helper.GetResourceMsgFromResourcetext("InvalidComputerName"), false, computername);
            }
        }//End BeginProcessing()
Exemple #26
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);
                }
            }
        }