Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Auto-start property in IIS 8 application pool for multiple servers

Tags:

powershell

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.

like image 556
shashank Avatar asked Dec 22 '14 22:12

shashank


1 Answers

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
}
}
}
like image 129
Abhishek Avatar answered Oct 13 '22 22:10

Abhishek