在IIS 8应用程序池中为多个服务器启用自动启动属性

时间:2014-12-22 22:31:00

标签: powershell

我想在IIS 8应用程序池中为power shell脚本中的多个服务器启用自动启动和启动模式属性。我创建了一个适用于单个服务器的脚本。见下文: -

Import-Module WebAdministration
cd IIS:/AppPools
$ApplicationPools = dir
foreach ($item in $ApplicationPools)
{
 $ApplicationPoolName = $item.Name
 $pool = Get-Item $ApplicationPoolName
 $pool.autoStart = 'false'
 $pool.startmode = 'ondemand'
 $pool | Set-Item
}

有人可以帮助我编辑多个服务器。我的所有服务器都在域中。

1 个答案:

答案 0 :(得分:7)

尝试下面的内容: -

$Servers = Get-Content C:\Users\Desktop\server.txt

$Servers | ForEach-Object {
            Invoke-Command -ComputerName $_ -ScriptBlock {
            Import-Module WebAdministration
            cd IIS:/Sites
            $Application = dir
foreach ($item in $Application)
{
    $ApplicationName = $item.Name
    $Website = Get-Item $ApplicationName
    $Website.serverAutoStart = 'true'
    $Website | Set-Item
}
            cd IIS:/AppPools
            $ApplicationPools = dir
foreach ($item in $ApplicationPools)
{
    $ApplicationPoolName = $item.Name
    $AppPool = Get-Item $ApplicationPoolName
    $AppPool.autoStart = 'true'
    $AppPool.startmode = 'alwaysrunning'
    $AppPool | Set-Item
}
}
}