如何使用Powershell脚本在IIS中启动和停止应用程序池 [英] How to start and stop application pool in IIS using powershell script

查看:724
本文介绍了如何使用Powershell脚本在IIS中启动和停止应用程序池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Powershell脚本在IIS中启动和停止应用程序池.我曾尝试编写脚本,但没有得到.

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.

推荐答案

您可以使用此

如果您使用(PowerShell 2.0)导入WebAdministration模块

import-module WebAdministration

请先检查应用程序池的状态. 如果应用程序池已经停止,则会出现异常.

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

停止应用程序池:

$applicationPoolName = 'DefaultAppPool'

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

启动应用程序池:

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

权限:您必须是"IIS Admins"组的成员.

这篇关于如何使用Powershell脚本在IIS中启动和停止应用程序池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆