I want to enable auto-start and start mode property in IIS 8 application pool for multiple servers from power shell script . I have created a script which works for single 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 someone help me with multiple servers editing.All my servers are in domain.
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
}
}
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With