[英]Set application settings in IIS through PowerShell
如何通过 PowerShell 在 IIS 中设置应用程序设置?
我尝试使用Set-WebConfigurationProperty
作为
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 身份验证更改为 Forms
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST/Somewebsite' -filter "system.web/authentication" -name "mode" -value "Forms"
你可以从这里学习如何做任何事情。
还有 get-webconfigurationproperty 命令可以在您编辑之前获取配置,这只是从 PowerShell 运行。
要记住的一个关键是SET-WebConfigurationProperty
将覆盖所有内容并且通常不会执行您想要的操作。
其中Add-WebConfigurationProperty
将添加,而不是覆盖和添加其他配置。
希望有帮助!
富有的
以及如何使用Add-WebConfigurationProperty
? 因为它必须在应用设置尚未丢失的情况下使用( Set-WebConfigurationProperty
将失败)。
因此,鉴于以下配置,站点“SiteOne”具有虚拟目录“VirtualDirOne”:
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="first" value="a" />
</appSettings>
</configuration>
当我想将值更改为“b”时:
Set-WebConfigurationProperty -pspath "iis:\Sites\SiteOne\VirtualDirOne" -filter "/appSettings/add[@key='first']" -name value -value "b"
当我想添加另一个设置时:
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']"
有很多例子在这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.