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

后端 未结 5 1086
小蘑菇
小蘑菇 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:49

    You can use this

    if your use (PowerShell 2.0) import WebAdministration module

    import-module WebAdministration
    

    Please check the state of the application pool before. If the application pool is already stopped you get an exception.

    Stop application pool:

    $applicationPoolName = 'DefaultAppPool'
    
    if((Get-WebAppPoolState -Name $applicationPoolName).Value -ne 'Stopped'){
        Write-Output ('Stopping Application Pool: {0}' -f $applicationPoolName)
        Stop-WebAppPool -Name $applicationPoolName
    } 
    

    Start application pool:

    if((Get-WebAppPoolState -Name $applicationPoolName).Value -ne 'Started'){
        Write-Output ('Starting Application Pool: {0}' -f $applicationPoolName)
        Start-WebAppPool -Name $applicationPoolName
    }
    

    Permissions: You have to be a member of the "IIS Admins" group.

提交回复
热议问题