【发布时间】:2020-03-07 12:07:16
【问题描述】:
所以我正在尝试使用 Stop-AppPool 停止 Web 服务器 AppPools。
我还想运行一个配置文件,允许我按名称排除任何 appPools。
在我的测试网络服务器上,我启动并运行了一个 config.xml 文件,它允许我将单个 AppPool 名称放入“密钥”,然后稍后在 Powershell 中将其拉出。具体适用的行是:
Powershell:
[xml]$configFile = get-content D:\Test\WebsiteDeployConfig.xml
$excluded_AppPools = $configFile.configuration.appSettings.add.value
XML 文件:
<?xml version="1.0"?>
<configuration>
<startup>
</startup>
<appSettings>
<!--Vars -->
<add key="apexclude" value="logging.mycompany.com"/>
<!-- I would like to ALSO axclude "Manufacturer1_Akamai" -->
<!--MoreVarsExample
<add key="var2" value="variableValue2"/>
-->
</appSettings>
</configuration>
这里的问题是当我开始尝试将多个 AppPools 添加到该“排除”列表中时。我确定这是一项 XML 技能,但我尝试添加第二个 AppPool 的格式似乎不起作用。
不仅格式不起作用,而且似乎我对 Key=apexclude xml 行或当我制作另一行时所做的任何事情,页面似乎不再停止 logging.mycompany.com。
所以我的问题是,如何在 config.xml 文件中添加第二个 AppPool 名称以便排除多个站点?
我试过了:
<add key="apexclude" value="logging.mycompany.com,Manufacturer1_Akamai"/>
<add key="apexclude" value="logging.mycompany.com;Manufacturer1_Akamai"/>
我尝试在工作行中添加一个具有相同和不同键值的新行
<add key="apexclude" value="logging.mycompany.com"/>
<add key="apexclude" value="Manufacturer1_Akamai"/>
我在这里不知所措。我最好的猜测是我必须将它们存储在一个数组中,但我不确定如何。
供参考:我的最终剧本目前是
import-module WebAdministration
import-module IISAdministration
[xml]$configFile = get-content D:\Test\WebsiteDeployConfig.xml
$excluded_AppPools = $configFile.configuration.appSettings.add.value
write-host 'the list of excluded AppPools is:'
write-host $configFile.configuration.appSettings.add.value
$sites = @(Get-ItemProperty -Path IIS:\AppPools\* | where-object {$_.Name -ne $excluded_AppPools})
write-host "The Following Pools are Slated to Stop"
write-host $sites.Name
foreach ($site in $sites) {
write-host "Stopping $_.Name"
#Stop-WebAppPool -Name $site
}
【问题讨论】:
-
你可以试试
string[] mykey = ConfigurationManager.AppSettings["mykey"].Split(','); .请参阅此链接以获取更多详细信息:stackoverflow.com/questions/2819964/… 和 stackoverflow.com/questions/32737620/…
标签: xml powershell iis