Enable autorun property in IIS 8 application pool for multiple servers

I want to enable autorun and run property in IIS 8 application pool for multiple servers from a shell script. I created a script that works for one server. see below: -

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
}

      

Can anyone help me with multiple servers. All my servers are on a domain.

+3


source to share


1 answer


Try below: -



$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
}
}
}

      

+6


source







All Articles