How to start and stop application pool in IIS using powershell script

后端 未结 5 1042
小蘑菇
小蘑菇 2021-02-19 19:53

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.

5条回答
  •  隐瞒了意图╮
    2021-02-19 20:52

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

提交回复
热议问题