通过PowerShell在IIS中设置应用程序设置
如何通过PowerShell在IIS中设置应用程序设置 我尝试使用通过PowerShell在IIS中设置应用程序设置,powershell,iis,Powershell,Iis,如何通过PowerShell在IIS中设置应用程序设置 我尝试使用将WebConfiguration属性设置为 Set-WebConfigurationProperty "/appSettings/add[@key='someKey']" -PSPath "IIS:\Sites\Default Web Site\someSite" -name "someKey" -Value "someValue" 但是我越来越 WARNING: Target configuration object '/a
将WebConfiguration属性设置为
Set-WebConfigurationProperty "/appSettings/add[@key='someKey']" -PSPath "IIS:\Sites\Default Web Site\someSite" -name "someKey" -Value "someValue"
但是我越来越
WARNING: Target configuration object '/appSettings/add[@key='someKey'] is not found at path 'MACHINE/WEBROOT/APPHOST/Default Web Site/someSite'.
我发现最简单的方法是从IIS配置编辑器构建PowerShell
这样做
1) 打开Inetmgr(IIS)
2) 单击要定位的站点。
3) 功能视图,配置编辑器位于左下角。
4) 从这里,浏览到要编辑的配置部分,然后
进行更改
5) 然后单击右上角的“生成脚本”
这将生成多个不同的脚本来配置它,选择PowerShell就可以了
例如,将Windows身份验证更改为窗体
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Somewebsite' -filter "system.web/authentication" -name "mode" -value "Forms"
你可以从这里学习如何做任何事情
还有get-webconfigurationproperty命令,它将在编辑配置之前获取配置,这只是从PowerShell运行的
要记住的一个关键点是设置WebConfiguration属性
将覆盖所有内容,并且通常不会执行您想要的操作
其中addwebconfigurationproperty
将添加,而不是覆盖和添加其他配置
希望有帮助
Rich以及如何准确使用添加WebConfigurationProperty
?因为它必须在应用程序设置丢失的情况下使用(Set WebConfigurationProperty
将失败)
因此,给定以下配置,一个带有虚拟目录“VirtualDirOne”的站点“SiteOne”:
当我要添加其他设置时:
Add-WebConfigurationProperty -pspath "iis:\Sites\SiteOne\VirtualDirOne" -filter "/appSettings" -name "." -value @{key='second'; value='x'}
当我想要获得值时:
Get-WebConfigurationProperty -pspath "iis:\Sites\SiteOne\VirtualDirOne" -filter "/appSettings/add[@key='second']" -name "value.Value"
最后,要删除该设置,请执行以下操作:
Clear-WebConfiguration -pspath "iis:\Sites\SiteOne\VirtualDirOne" -filter "/appSettings/add[@key='second']"
有很多例子。这比我所做的要容易得多。谢谢
Get-WebConfigurationProperty -pspath "iis:\Sites\SiteOne\VirtualDirOne" -filter "/appSettings/add[@key='second']" -name "value.Value"
Clear-WebConfiguration -pspath "iis:\Sites\SiteOne\VirtualDirOne" -filter "/appSettings/add[@key='second']"