Ejemplo n.º 1
0
 protected override void SetItem(string path, object value)
 {
     if (value == null)
     {
         throw new ArgumentException(this.helper.GetResourceMsgFromResourcetext("value"));
     }
     string str = string.Empty;
     if ((path.Length == 0) && string.IsNullOrEmpty(str))
     {
         this.AssertError(this.helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
     }
     else
     {
         char ch = '\\';
         if (path.Contains(ch.ToString()))
         {
             str = path.Substring(path.LastIndexOf('\\') + 1);
         }
         else
         {
             str = path;
         }
         if (str.Equals(path, StringComparison.OrdinalIgnoreCase))
         {
             this.AssertError(this.helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
         }
         else
         {
             if (!this.clearItemIsCalled)
             {
                 value = this.ValidateAndGetUserObject(str, value);
                 if (value == null)
                 {
                     return;
                 }
             }
             else if (string.Equals(str, "RunAsPassword", StringComparison.OrdinalIgnoreCase))
             {
                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("ClearItemOnRunAsPassword"), false);
                 return;
             }
             string verboseDescription = string.Format(CultureInfo.CurrentUICulture, this.helper.GetResourceMsgFromResourcetext("SetItemWhatIfAndConfirmText"), new object[] { path, value });
             if (base.ShouldProcess(verboseDescription, "", ""))
             {
                 path = path.Substring(0, path.LastIndexOf(str, StringComparison.OrdinalIgnoreCase));
                 string hostName = this.GetHostName(path);
                 string resourceURI = this.NormalizePath(path, hostName);
                 if (this.IsPathLocalMachine(hostName) && !this.IsWSManServiceRunning())
                 {
                     WSManHelper.ThrowIfNotAdministrator();
                     this.StartWSManService((bool) base.Force);
                 }
                 bool flag = false;
                 lock (WSManHelper.AutoSession)
                 {
                     object obj2;
                     Dictionary<string, object> sessionObjCache = WSManHelper.GetSessionObjCache();
                     sessionObjCache.TryGetValue(hostName, out obj2);
                     List<string> list = new List<string>();
                     char ch2 = '\\';
                     if (path.EndsWith(ch2.ToString(), StringComparison.OrdinalIgnoreCase))
                     {
                         path = path.Remove(path.LastIndexOf('\\'));
                     }
                     string str5 = hostName + '\\';
                     if (path.Contains(str5 + "Listener"))
                     {
                         this.SetItemListenerOrClientCertificate(obj2, resourceURI, PKeyListener, str, value, path, "Listener", hostName);
                     }
                     else if (path.Contains(str5 + "ClientCertificate"))
                     {
                         this.SetItemListenerOrClientCertificate(obj2, resourceURI, PKeyCertMapping, str, value, path, "ClientCertificate", hostName);
                     }
                     else
                     {
                         if (path.Contains(str5 + "Plugin"))
                         {
                             if (path.EndsWith(str5 + "Plugin", StringComparison.OrdinalIgnoreCase))
                             {
                                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
                             }
                             try
                             {
                                 XmlDocument xmlPlugins = this.FindResourceValue(obj2, resourceURI, null);
                                 string currentPluginName = string.Empty;
                                 this.GetPluginNames(xmlPlugins, out this.objPluginNames, out currentPluginName, path);
                                 if (string.IsNullOrEmpty(currentPluginName))
                                 {
                                     if (!this.clearItemIsCalled)
                                     {
                                         this.AssertError(this.helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                                     }
                                     goto Label_0CC5;
                                 }
                                 string str7 = resourceURI + "?Name=" + currentPluginName;
                                 CurrentConfigurations configurations = new CurrentConfigurations((IWSManSession) obj2);
                                 string responseOfGet = this.GetResourceValueInXml((IWSManSession) obj2, str7, null);
                                 configurations.RefreshCurrentConfiguration(responseOfGet);
                                 XmlDocument rootDocument = configurations.RootDocument;
                                 ArrayList arrSecurity = null;
                                 ArrayList list3 = this.ProcessPluginResourceLevel(rootDocument, out arrSecurity);
                                 ArrayList list4 = this.ProcessPluginInitParamLevel(rootDocument);
                                 try
                                 {
                                     configurations.RemoveOneConfiguration("./attribute::xml:lang");
                                 }
                                 catch (ArgumentException)
                                 {
                                 }
                                 str5 = str5 + "Plugin" + '\\';
                                 if (path.EndsWith(str5 + currentPluginName, StringComparison.OrdinalIgnoreCase))
                                 {
                                     if ("RunAsUser".Equals(str, StringComparison.OrdinalIgnoreCase))
                                     {
                                         PSCredential credential = value as PSCredential;
                                         if (credential != null)
                                         {
                                             value = credential.UserName;
                                             configurations.UpdateOneConfiguration(".", "RunAsPassword", this.GetStringFromSecureString(credential.Password));
                                         }
                                     }
                                     if ("RunAsPassword".Equals(str, StringComparison.OrdinalIgnoreCase))
                                     {
                                         if (string.IsNullOrEmpty(configurations.GetOneConfiguration(string.Format(CultureInfo.InvariantCulture, "./attribute::{0}", new object[] { "RunAsUser" }))))
                                         {
                                             this.AssertError(this.helper.GetResourceMsgFromResourcetext("SetItemOnRunAsPasswordNoRunAsUser"), false);
                                         }
                                         value = this.GetStringFromSecureString(value);
                                     }
                                     configurations.UpdateOneConfiguration(".", str, value.ToString());
                                 }
                                 str5 = str5 + currentPluginName + '\\';
                                 if (path.Contains(str5 + "Resources"))
                                 {
                                     if (path.EndsWith(str5 + "Resources", StringComparison.OrdinalIgnoreCase))
                                     {
                                         this.AssertError(this.helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
                                         goto Label_0CC5;
                                     }
                                     str5 = str5 + "Resources" + '\\';
                                     int index = path.IndexOf('\\', str5.Length);
                                     string str9 = string.Empty;
                                     if (index == -1)
                                     {
                                         str9 = path.Substring(str5.Length);
                                     }
                                     else
                                     {
                                         str9 = path.Substring(str5.Length, path.IndexOf('\\', str5.Length) - str5.Length);
                                     }
                                     if (path.Contains(str5 + str9))
                                     {
                                         if (path.EndsWith(str5 + str9, StringComparison.OrdinalIgnoreCase))
                                         {
                                             if (list3 == null)
                                             {
                                                 goto Label_0CC5;
                                             }
                                             if (str.Equals("ResourceUri", StringComparison.OrdinalIgnoreCase))
                                             {
                                                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("NoChangeValue"), false);
                                                 goto Label_0CC5;
                                             }
                                             foreach (PSObject obj3 in list3)
                                             {
                                                 if (str9.Equals(obj3.Properties["ResourceDir"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                                 {
                                                     string pathToNodeFromRoot = string.Format(CultureInfo.InvariantCulture, "{0}:{1}/{0}:{2}[attribute::{3}='{4}']", new object[] { "defaultNameSpace", "Resources", "Resource", "ResourceUri", obj3.Properties["ResourceUri"].Value.ToString() });
                                                     if (!obj3.Properties[str].Value.ToString().Equals("Container"))
                                                     {
                                                         configurations.UpdateOneConfiguration(pathToNodeFromRoot, str, value.ToString());
                                                     }
                                                     else
                                                     {
                                                         this.AssertError(this.helper.GetResourceMsgFromResourcetext("NoChangeValue"), false);
                                                     }
                                                 }
                                             }
                                         }
                                         str5 = str5 + str9 + '\\';
                                         if (path.Contains(str5 + "Security"))
                                         {
                                             if (path.EndsWith(str5 + "Security", StringComparison.OrdinalIgnoreCase))
                                             {
                                                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("NoChangeValue"), false);
                                                 goto Label_0CC5;
                                             }
                                             if (arrSecurity == null)
                                             {
                                                 goto Label_0CC5;
                                             }
                                             if (path.Contains(string.Concat(new object[] { str5, "Security", '\\', "Security_" })))
                                             {
                                                 flag = true;
                                                 foreach (PSObject obj4 in arrSecurity)
                                                 {
                                                     if (path.Substring(path.LastIndexOf('\\') + 1, path.Length - (path.LastIndexOf('\\') + 1)).Equals(obj4.Properties["SecurityDIR"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                                     {
                                                         if (base.Force == 0)
                                                         {
                                                             string resourceMsgFromResourcetext = this.helper.GetResourceMsgFromResourcetext("ShouldContinueSecurityQuery");
                                                             resourceMsgFromResourcetext = string.Format(CultureInfo.CurrentCulture, resourceMsgFromResourcetext, new object[] { currentPluginName });
                                                             if (!base.ShouldContinue(resourceMsgFromResourcetext, this.helper.GetResourceMsgFromResourcetext("ShouldContinueSecurityCaption")))
                                                             {
                                                                 goto Label_0CC5;
                                                             }
                                                         }
                                                         string str13 = string.Format(CultureInfo.InvariantCulture, "{0}:{1}/{0}:{2}[@{6}='{7}']/{0}:{3}[@{4}='{5}']", new object[] { "defaultNameSpace", "Resources", "Resource", "Security", "Uri", obj4.Properties["Uri"].Value.ToString(), "ResourceUri", obj4.Properties["ParentResourceUri"].Value.ToString() });
                                                         configurations.UpdateOneConfiguration(str13, str, value.ToString());
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                                 else if (path.EndsWith(str5 + "InitializationParameters", StringComparison.OrdinalIgnoreCase))
                                 {
                                     foreach (PSObject obj5 in list4)
                                     {
                                         if (obj5.Properties[str] != null)
                                         {
                                             string str14 = string.Format(CultureInfo.InvariantCulture, "{0}:{1}/{0}:{2}[@{3}='{4}']", new object[] { "defaultNameSpace", "InitializationParameters", "Param", "Name", obj5.Properties[str].Name });
                                             configurations.UpdateOneConfiguration(str14, "Value", value.ToString());
                                             break;
                                         }
                                     }
                                 }
                                 else if (path.EndsWith(str5 + "Quotas", StringComparison.OrdinalIgnoreCase))
                                 {
                                     string str15 = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { "defaultNameSpace", "Quotas" });
                                     configurations.UpdateOneConfiguration(str15, str, value.ToString());
                                     if (ppqWarningConfigurations.Contains(str.ToLowerInvariant()))
                                     {
                                         string str16 = str;
                                         if (str.Equals("IdleTimeoutms", StringComparison.InvariantCultureIgnoreCase))
                                         {
                                             str16 = "IdleTimeout";
                                         }
                                         string str17 = string.Format(CultureInfo.InvariantCulture, @"{0}:\{1}\{2}\{3}", new object[] { "WSMan", hostName, "Shell", str16 });
                                         list.Add(string.Format(this.helper.GetResourceMsgFromResourcetext("SetItemWarnigForPPQ"), str17));
                                     }
                                 }
                                 sessionObjCache.TryGetValue(hostName, out obj2);
                                 string resourceUri = string.Format(CultureInfo.InvariantCulture, "{0}?Name={1}", new object[] { resourceURI, currentPluginName });
                                 try
                                 {
                                     configurations.PutConfiguraitonOnServer(resourceUri);
                                     if (!flag)
                                     {
                                         if (this.IsPathLocalMachine(hostName))
                                         {
                                             list.Add(this.helper.GetResourceMsgFromResourcetext("SetItemServiceRestartWarning"));
                                         }
                                         else
                                         {
                                             list.Add(string.Format(this.helper.GetResourceMsgFromResourcetext("SetItemServiceRestartWarningRemote"), hostName));
                                         }
                                     }
                                 }
                                 finally
                                 {
                                     if (!string.IsNullOrEmpty(configurations.ServerSession.Error))
                                     {
                                         this.AssertError(configurations.ServerSession.Error, true);
                                     }
                                 }
                                 goto Label_0C82;
                             }
                             catch (PSArgumentException)
                             {
                                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                                 goto Label_0CC5;
                             }
                             catch (PSArgumentNullException)
                             {
                                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                                 goto Label_0CC5;
                             }
                             catch (NullReferenceException)
                             {
                                 this.AssertError(this.helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                                 goto Label_0CC5;
                             }
                         }
                         try
                         {
                             Hashtable hashtable = new Hashtable();
                             if (str.Equals("TrustedHosts", StringComparison.OrdinalIgnoreCase) || str.Equals("RootSDDL", StringComparison.OrdinalIgnoreCase))
                             {
                                 if (value.GetType().FullName.Equals("System.String"))
                                 {
                                     if (base.Force == 0)
                                     {
                                         string query = "";
                                         string caption = this.helper.GetResourceMsgFromResourcetext("SetItemGeneralSecurityCaption");
                                         if (str.Equals("TrustedHosts", StringComparison.OrdinalIgnoreCase))
                                         {
                                             query = this.helper.GetResourceMsgFromResourcetext("SetItemTrustedHostsWarningQuery");
                                         }
                                         else if (str.Equals("RootSDDL", StringComparison.OrdinalIgnoreCase))
                                         {
                                             query = this.helper.GetResourceMsgFromResourcetext("SetItemRootSDDLWarningQuery");
                                         }
                                         if (!base.ShouldContinue(query, caption))
                                         {
                                             goto Label_0CC5;
                                         }
                                     }
                                     WSManProviderSetItemDynamicParameters dynamicParameters = base.DynamicParameters as WSManProviderSetItemDynamicParameters;
                                     if (((dynamicParameters != null) && (dynamicParameters.Concatenate != 0)) && !string.IsNullOrEmpty(value.ToString()))
                                     {
                                         value = this.SplitAndUpdateStringUsingDelimiter(obj2, resourceURI, str, value.ToString(), ",");
                                     }
                                     hashtable.Add(str, value);
                                 }
                                 else
                                 {
                                     this.AssertError(this.helper.GetResourceMsgFromResourcetext("TrustedHostValueTypeError"), false);
                                 }
                             }
                             else
                             {
                                 hashtable.Add(str, value);
                                 if (globalWarningUris.Contains(resourceURI) && globalWarningConfigurations.Contains(str.ToLowerInvariant()))
                                 {
                                     list.Add(string.Format(this.helper.GetResourceMsgFromResourcetext("SetItemWarningForGlobalQuota"), value));
                                 }
                             }
                             this.PutResourceValue(obj2, resourceURI, hashtable, hostName);
                         }
                         catch (COMException exception)
                         {
                             this.AssertError(exception.Message, false);
                             goto Label_0CC5;
                         }
                     }
                 Label_0C82:
                     foreach (string str21 in list)
                     {
                         base.WriteWarning(str21);
                     }
                 Label_0CC5:;
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        protected override void SetItem(string path, object value)
        {

            if (null == value)
            {
                throw new ArgumentException(helper.GetResourceMsgFromResourcetext("value"));
            }

            string ChildName = string.Empty;

            if (path.Length == 0 && String.IsNullOrEmpty(ChildName))
            {
                AssertError(helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
                return;
            }


            if (path.Contains(WSManStringLiterals.DefaultPathSeparator.ToString()))
            {
                //Get the ChildName
                ChildName = path.Substring(path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator) + 1);
            }
            else
            {
                ChildName = path;
            }

            if (ChildName.Equals(path, StringComparison.OrdinalIgnoreCase))
            {
                AssertError(helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
                return;
            }

            if (!this.clearItemIsCalled)
            {
                value = this.ValidateAndGetUserObject(ChildName, value);

                // The value will be Null only if the object provided by User is not of accepted type.
                // As of now, this can only happen in case of RunAsUserName and RunAsPassword
                if (value == null)
                {
                    return;
                }
            }
            else
            {
                // If validation is not required, that means Clear-Item cmdlet is called.
                // Clear-Item is not allowed on RunAsPassword, Admin should call Clear-Item RunAsUser 
                // if he intends to disable RunAs on the Plugin.
                if(String.Equals(ChildName, WSManStringLiterals.ConfigRunAsPasswordName, StringComparison.OrdinalIgnoreCase))
                {
                    AssertError(helper.GetResourceMsgFromResourcetext("ClearItemOnRunAsPassword"), false);
                    return;
                }
            }

            string whatIfMessage = String.Format(CultureInfo.CurrentUICulture, helper.GetResourceMsgFromResourcetext("SetItemWhatIfAndConfirmText"), path, value);
            if (!ShouldProcess(whatIfMessage, "", ""))
            {
                return;
            }

            path = path.Substring(0, path.LastIndexOf(ChildName, StringComparison.OrdinalIgnoreCase));

            //Get the wsman host name to find the session object
            string host = GetHostName(path);
            string uri = NormalizePath(path, host);

            //Chk for Winrm Service
            if (IsPathLocalMachine(host))
            {
                if (!IsWSManServiceRunning())
                {
                    WSManHelper.ThrowIfNotAdministrator();
                    StartWSManService(this.Force);
                }
            }

            bool settingPickedUpDynamically = false;

            lock(WSManHelper.AutoSession)
            {
                //Gets the session object from the cache.
                object sessionobj;
                Dictionary<string, object> SessionObjCache = WSManHelper.GetSessionObjCache();
                SessionObjCache.TryGetValue(host, out sessionobj);

                List<String> warningMessage = new List<string>();

                //if endswith '\', removes it.
                if (path.EndsWith(WSManStringLiterals.DefaultPathSeparator.ToString(), StringComparison.OrdinalIgnoreCase))
                {
                    path = path.Remove(path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator));
                }
                string strPathChk = host + WSManStringLiterals.DefaultPathSeparator;
                if (path.Contains(strPathChk + WSManStringLiterals.containerListener))
                {
                    SetItemListenerOrClientCertificate(sessionobj, uri, PKeyListener, ChildName, value, path, WSManStringLiterals.containerListener, host);
                }
                else if (path.Contains(strPathChk + WSManStringLiterals.containerClientCertificate))
                {
                    SetItemListenerOrClientCertificate(sessionobj, uri, PKeyCertMapping, ChildName, value, path, WSManStringLiterals.containerClientCertificate, host);
                }
                else if (path.Contains(strPathChk + WSManStringLiterals.containerPlugin))
                {
                    if (path.EndsWith(strPathChk + WSManStringLiterals.containerPlugin, StringComparison.OrdinalIgnoreCase))
                    {
                        AssertError(helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
                    }
                    try
                    {
                        XmlDocument xmlPlugins = FindResourceValue(sessionobj, uri, null);
                        string currentpluginname = string.Empty;
                        GetPluginNames(xmlPlugins, out objPluginNames, out currentpluginname, path);
                        if (String.IsNullOrEmpty(currentpluginname))
                        {
                            if (!this.clearItemIsCalled)
                            {
                                // Don't need an error if ClearItem is called.
                                AssertError(helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                            }
                            return;
                        }
                        string filter = uri + "?Name=" + currentpluginname;

                        CurrentConfigurations pluginConfiguration = new CurrentConfigurations((IWSManSession)sessionobj);
                        
                        string pluginXML = this.GetResourceValueInXml((IWSManSession)sessionobj, filter, null);
                        pluginConfiguration.RefreshCurrentConfiguration(pluginXML);
                        
                        XmlDocument CurrentPluginXML = pluginConfiguration.RootDocument;

                        ArrayList arrSecurity = null;
                        ArrayList arrResources = ProcessPluginResourceLevel(CurrentPluginXML, out arrSecurity);
                        ArrayList arrInitParams = ProcessPluginInitParamLevel(CurrentPluginXML);

                        try
                        {
                            // Remove XML:LANG attribute if present.
                            // If not present ignore the exception.
                            pluginConfiguration.RemoveOneConfiguration("./attribute::xml:lang");
                        }
                        catch (ArgumentException)
                        { }

                        strPathChk = strPathChk + WSManStringLiterals.containerPlugin + WSManStringLiterals.DefaultPathSeparator;
                        if (path.EndsWith(strPathChk + currentpluginname, StringComparison.OrdinalIgnoreCase))
                        {
                            if (WSManStringLiterals.ConfigRunAsUserName.Equals(ChildName, StringComparison.OrdinalIgnoreCase))
                            {
                                PSCredential runAsCredentials = value as PSCredential;

                                if (runAsCredentials != null)
                                {
                                    // UserName
                                    value = runAsCredentials.UserName;

                                    pluginConfiguration.UpdateOneConfiguration(
                                        ".",
                                        WSManStringLiterals.ConfigRunAsPasswordName,
                                        this.GetStringFromSecureString(runAsCredentials.Password));
                                }
                            }

                            if (WSManStringLiterals.ConfigRunAsPasswordName.Equals(ChildName, StringComparison.OrdinalIgnoreCase))
                            {
                                if(String.IsNullOrEmpty(
                                    pluginConfiguration.GetOneConfiguration(
                                        String.Format(
                                            CultureInfo.InvariantCulture, 
                                            "./attribute::{0}", 
                                            WSManStringLiterals.ConfigRunAsUserName))))
                                {
                                    // User Cannot set RunAsPassword if, RunAsUser is not present.
                                    AssertError(helper.GetResourceMsgFromResourcetext("SetItemOnRunAsPasswordNoRunAsUser"), false);
                                }

                                value = this.GetStringFromSecureString(value);
                            }

                            pluginConfiguration.UpdateOneConfiguration(".", ChildName, value.ToString());
                        }
                        strPathChk = strPathChk + currentpluginname + WSManStringLiterals.DefaultPathSeparator;
                        if (path.Contains(strPathChk + WSManStringLiterals.containerResources))
                        {
                            if (path.EndsWith(strPathChk + WSManStringLiterals.containerResources, StringComparison.OrdinalIgnoreCase))
                            {
                                AssertError(helper.GetResourceMsgFromResourcetext("SetItemNotSupported"), false);
                                return;

                            }
                            strPathChk = strPathChk + WSManStringLiterals.containerResources + WSManStringLiterals.DefaultPathSeparator;
                            int Sepindex = path.IndexOf(WSManStringLiterals.DefaultPathSeparator, strPathChk.Length);
                            string sResourceDirName = string.Empty;
                            if (Sepindex == -1)
                            {
                                sResourceDirName = path.Substring(strPathChk.Length);
                            }
                            else
                            {
                                sResourceDirName = path.Substring(strPathChk.Length, path.IndexOf(WSManStringLiterals.DefaultPathSeparator, strPathChk.Length) - (strPathChk.Length));
                            }
                            if (path.Contains(strPathChk + sResourceDirName))
                            {
                                if (path.EndsWith(strPathChk + sResourceDirName, StringComparison.OrdinalIgnoreCase))
                                {
                                    if (null == arrResources)
                                    {
                                        return;
                                    }

                                    if (ChildName.Equals(WSManStringLiterals.ConfigResourceUriName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        AssertError(helper.GetResourceMsgFromResourcetext("NoChangeValue"), false);
                                        return;
                                    }

                                    foreach (PSObject p in arrResources)
                                    {
                                        if (sResourceDirName.Equals(p.Properties["ResourceDir"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                        {
                                            string xpathToUse = String.Format(
                                                CultureInfo.InvariantCulture,
                                                "{0}:{1}/{0}:{2}[attribute::{3}='{4}']",
                                                CurrentConfigurations.DefaultNameSpacePrefix,
                                                WSManStringLiterals.containerResources,
                                                WSManStringLiterals.containerSingleResource,
                                                WSManStringLiterals.ConfigResourceUriName,
                                                p.Properties[WSManStringLiterals.ConfigResourceUriName].Value.ToString());
                                            
                                            if (!p.Properties[ChildName].Value.ToString().Equals(WSManStringLiterals.ContainerChildValue))
                                            {
                                                // Allow Set-Item on non-container values only.
                                                pluginConfiguration.UpdateOneConfiguration(xpathToUse, ChildName, value.ToString());
                                            }
                                            else
                                            {
                                                AssertError(helper.GetResourceMsgFromResourcetext("NoChangeValue"), false);
                                            }
                                        }
                                    }
                                }
                                strPathChk = strPathChk + sResourceDirName + WSManStringLiterals.DefaultPathSeparator;
                                if (path.Contains(strPathChk + WSManStringLiterals.containerSecurity))
                                {
                                    if (path.EndsWith(strPathChk + WSManStringLiterals.containerSecurity, StringComparison.OrdinalIgnoreCase))
                                    {
                                        AssertError(helper.GetResourceMsgFromResourcetext("NoChangeValue"), false);
                                        return;
                                    }

                                    if (null == arrSecurity)
                                    {
                                        return;
                                    }

                                    if (path.Contains(strPathChk + WSManStringLiterals.containerSecurity + WSManStringLiterals.DefaultPathSeparator + WSManStringLiterals.containerSecurity + "_"))
                                    {
                                        // Any setting inside security for plugin is picked up by service dynamically
                                        settingPickedUpDynamically = true;

                                        foreach (PSObject p in arrSecurity)
                                        {
                                            string sSecurityDirName = path.Substring(path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator) + 1, path.Length - (path.LastIndexOf(WSManStringLiterals.DefaultPathSeparator) + 1));
                                            if (sSecurityDirName.Equals(p.Properties["SecurityDIR"].Value.ToString(), StringComparison.OrdinalIgnoreCase))
                                            {
                                                if (!Force)
                                                {
                                                    string query = helper.GetResourceMsgFromResourcetext("ShouldContinueSecurityQuery");
                                                    query = String.Format(CultureInfo.CurrentCulture, query, currentpluginname);
                                                    if (!ShouldContinue(query, helper.GetResourceMsgFromResourcetext("ShouldContinueSecurityCaption")))
                                                    {
                                                        return;
                                                    }
                                                }

                                                //NameSpace:Resources/NameSpace:Resource[@ResourceUri={''}]/NameSpace:Security[@Uri='{2}']
                                                string xpathToUse = String.Format(
                                                    CultureInfo.InvariantCulture,
                                                    "{0}:{1}/{0}:{2}[@{6}='{7}']/{0}:{3}[@{4}='{5}']",
                                                    CurrentConfigurations.DefaultNameSpacePrefix,
                                                    WSManStringLiterals.containerResources,
                                                    WSManStringLiterals.containerSingleResource,
                                                    WSManStringLiterals.containerSecurity,
                                                    WSManStringLiterals.ConfigSecurityUri,
                                                    p.Properties[WSManStringLiterals.ConfigSecurityUri].Value.ToString(),
                                                    WSManStringLiterals.ConfigResourceUriName,
                                                    p.Properties["ParentResourceUri"].Value.ToString());

                                                pluginConfiguration.UpdateOneConfiguration(xpathToUse, ChildName, value.ToString());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        else if (path.EndsWith(strPathChk + WSManStringLiterals.containerInitParameters, StringComparison.OrdinalIgnoreCase))
                        {
                            foreach (PSObject p in arrInitParams)
                            {
                                if (p.Properties[ChildName] != null)
                                {
                                    string xpathToUse = String.Format(
                                        CultureInfo.InvariantCulture,
                                        "{0}:{1}/{0}:{2}[@{3}='{4}']",
                                        CurrentConfigurations.DefaultNameSpacePrefix,
                                        WSManStringLiterals.containerInitParameters,
                                        WSManStringLiterals.ConfigInitializeParameterTag,
                                        WSManStringLiterals.ConfigInitializeParameterName,
                                        p.Properties[ChildName].Name);

                                    pluginConfiguration.UpdateOneConfiguration(xpathToUse, WSManStringLiterals.ConfigInitializeParameterValue, value.ToString());

                                    break;
                                }
                            }
                        }
                        else if (path.EndsWith(strPathChk + WSManStringLiterals.containerQuotasParameters, StringComparison.OrdinalIgnoreCase))
                        {
                            string xpathToUse = String.Format(
                                CultureInfo.InvariantCulture,
                                "{0}:{1}",
                                CurrentConfigurations.DefaultNameSpacePrefix,
                                WSManStringLiterals.containerQuotasParameters);

                            pluginConfiguration.UpdateOneConfiguration(xpathToUse, ChildName, value.ToString());

                            if (ppqWarningConfigurations.Contains(ChildName.ToLowerInvariant()))
                            {
                                string adjustedChileName = ChildName;

                                if (ChildName.Equals("IdleTimeoutms", StringComparison.OrdinalIgnoreCase))
                                {
                                    adjustedChileName = "IdleTimeout";
                                }

                                string pathForGlobalQuota = 
                                    String.Format(
                                        CultureInfo.InvariantCulture, 
                                        @"{0}:\{1}\{2}\{3}",
                                        WSManStringLiterals.rootpath,
                                        host,
                                        WSManStringLiterals.containerShell,
                                        adjustedChileName);

                                warningMessage.Add(String.Format(helper.GetResourceMsgFromResourcetext("SetItemWarnigForPPQ"), pathForGlobalQuota));
                            }
                        }

                        SessionObjCache.TryGetValue(host, out sessionobj);
                        string resourceUri = String.Format(
                            CultureInfo.InvariantCulture,
                            "{0}?Name={1}",
                            uri,
                            currentpluginname);

                        try
                        {
                            pluginConfiguration.PutConfiguraitonOnServer(resourceUri);

                            // Show Win RM service restart warning only when the changed setting is not picked up dynamically
                            if (settingPickedUpDynamically == false)
                            {
                                if (IsPathLocalMachine(host))
                                {
                                    warningMessage.Add(helper.GetResourceMsgFromResourcetext("SetItemServiceRestartWarning"));
                                }
                                else
                                {
                                    warningMessage.Add(String.Format(helper.GetResourceMsgFromResourcetext("SetItemServiceRestartWarningRemote"), host));
                                }
                            }
                        }
                        finally
                        {
                            if (!String.IsNullOrEmpty(pluginConfiguration.ServerSession.Error))
                            {
                                AssertError(pluginConfiguration.ServerSession.Error, true);
                            }
                        }
                    }
                    catch (PSArgumentException)
                    {
                        AssertError(helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                        return;
                    }
                    catch (PSArgumentNullException)
                    {
                        AssertError(helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                        return;
                    }
                    catch (NullReferenceException)
                    {
                        AssertError(helper.GetResourceMsgFromResourcetext("ItemDoesNotExist"), false);
                        return;
                    }
                }
                else
                {
                    try
                    {
                        Hashtable cmdlinevalue = new Hashtable();
                        if (ChildName.Equals("TrustedHosts", StringComparison.OrdinalIgnoreCase) || ChildName.Equals("RootSDDL", StringComparison.OrdinalIgnoreCase))
                        {
                            if (value.GetType().FullName.Equals("System.String"))
                            {
                                if (!Force)
                                {
                                    string query="";
                                    string caption = helper.GetResourceMsgFromResourcetext("SetItemGeneralSecurityCaption");
                                    if (ChildName.Equals("TrustedHosts", StringComparison.OrdinalIgnoreCase))
                                    {
                                        query = helper.GetResourceMsgFromResourcetext("SetItemTrustedHostsWarningQuery");
                                    }
                                    else if (ChildName.Equals("RootSDDL", StringComparison.OrdinalIgnoreCase))
                                    {
                                        query = helper.GetResourceMsgFromResourcetext("SetItemRootSDDLWarningQuery");
                                    }
                                    if (!ShouldContinue(query, caption))
                                    {
                                        return;
                                    }
                                }
                                WSManProviderSetItemDynamicParameters dynParams = DynamicParameters as WSManProviderSetItemDynamicParameters;
                                if (dynParams != null)
                                {
                                    if (dynParams.Concatenate)
                                    {
                                        if (!String.IsNullOrEmpty(value.ToString()))
                                        {
                                            // ',' is used as the delimiter in WSMan for TrustedHosts.
                                            value = SplitAndUpdateStringUsingDelimiter(sessionobj, uri, ChildName, value.ToString(), ",");
                                        }
                                    }
                                }
                                cmdlinevalue.Add(ChildName, value);
                            }
                            else
                            {
                                AssertError(helper.GetResourceMsgFromResourcetext("TrustedHostValueTypeError"), false);
                            }
                        }
                        else
                        {
                            cmdlinevalue.Add(ChildName, value);

                            if (globalWarningUris.Contains(uri) && globalWarningConfigurations.Contains(ChildName.ToLowerInvariant()))
                            {
                                warningMessage.Add(String.Format(helper.GetResourceMsgFromResourcetext("SetItemWarningForGlobalQuota"), value));
                            }
                        }
                        PutResourceValue(sessionobj, uri, cmdlinevalue, host);
                    }
                    catch (COMException e)
                    {
                        AssertError(e.Message, false);
                        return;
                    }
                }

                foreach(String warnings in warningMessage)
                {
                    WriteWarning(warnings);
                }
            }
        }