如何使用PowerShell远程检查Web应用程序池的状态? [英] How to remotely check the status of a web application pool with PowerShell?

查看:348
本文介绍了如何使用PowerShell远程检查Web应用程序池的状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行IIS7的Web服务器上看到了许多用于回收应用程序池的脚本,但有没有办法通过PowerShell检查Web应用程序池是在运行还是已停止?我似乎无法找到远程让Get-WebAppPoolState返回应用程序池状态的方法,而我的Google-fu无法提供替代品。我可以远程获取gwmi工作和回收或启动我的应用程序池,但理想情况下我只想在实际停止应用程序池时运行它。

I see a lot of scripts for recycling application pools on a web server running IIS7 but is there a way to check, with PowerShell, that the web application pool is running or stopped? I can't seem to figure out a way to remotely have Get-WebAppPoolState return the status on the Application Pool, and my Google-fu has not been able to come up with a replacement. I can remotely get gwmi to work and recycle or start my app pools but ideally I only want to have to run this if the app pool is actually stopped.

我需要吗?使用PSExec解决这个问题,或者有一个替代方案我可以使用类似于gwmi并使用一行命令来调用IIS7服务器上的应用程序池并给我状态吗?

Would I need to work this out with PSExec or is there an alternative I can use similar to gwmi and have a one line command to call the app pool on the IIS7 server and give me the status?

推荐答案

您可以使用Invoke-Command在远程计算机上调用Get-WebAppPoolState cmdlet。

You can use Invoke-Command to invoke the Get-WebAppPoolState cmdlet on the remote machine.

$appPoolStatus = Invoke-Command -ComputerName RemoteHostName {Import-Module WebAdministration; Get-WebAppPoolState DefaultAppPool}
$appPoolStatus.Value

请注意,如果您打算使用在调用机器上本地定义的变量,您将不得不根据规则对其进行处理。这个链接是一个很好的帖子解释它们:

Note that if you are going to use variables defined locally on the calling machine, you will have to treat them according to the rules. This link is an excellent post explaining them:

http://blogs.msdn.com/b/powershell/archive/2009/12/29/arguments-for-remote-commands.aspx

示例:

$appPoolName = "SomeAppPoolName"
$appPoolStatus = Invoke-Command -ComputerName RemoteHostName { param($apn) Import-Module WebAdministration; Get-WebAppPoolState $apn} -Args $appPoolName

这篇关于如何使用PowerShell远程检查Web应用程序池的状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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