I want to start and stop application pool in IIS using powershell script. I had try to write the script but i didn\'t get this.
You can stop and stop all application pools respectively using the following powershell script. The second line below elevates permissions. You could exclude this and just run as administrator.
Stop all application pools script
Import-Module WebAdministration
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
$AppPools=Get-ChildItem IIS:\AppPools | Where {$_.State -eq "Started"}
ForEach($AppPool in $AppPools)
{
Stop-WebAppPool -name $AppPool.name
# Write-Output ('Stopping Application Pool: {0}' -f $AppPool.name)
}
Start all application pools script
Import-Module WebAdministration
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }
$AppPools=Get-ChildItem IIS:\AppPools | Where {$_.State -eq "Stopped"}
ForEach($AppPool in $AppPools)
{
Start-WebAppPool -name $AppPool.name
# Write-Output ('Starting Application Pool: {0}' -f $AppPool.name)
}