【发布时间】:2013-12-14 02:03:08
【问题描述】:
Similar to this question here 我正在尝试监控一组网站链接是否启动并运行或没有响应。我在 Internet 上找到了相同的 PowerShell 脚本。
但是,我需要检查更具体的链接,而不是直接的网站链接,例如:
http://mypage.global/Chemical/
http://maypage2:9080/portal/site/hotpot/
当我尝试检查这些链接的状态时,我得到以下输出:
URL StatusCode StatusDescription ResponseLength TimeTaken
http://mypage.global/Chemical/ 0
http://maypage2:9080/portal/site/hotpot/ 0
以上链接需要我连接到VPN,但我可以从浏览器访问这些链接。
Invoke-WebRequest -Uri https://stackoverflow.com/questions/20259251/powershell-script-to-check-the-status-of-a-url 的输出:
PS C:\Users\682126> Invoke-WebRequest -Uri https://stackoverflow.com/questions/20259251/powershell-script-to-check-the-status-of-a-url
The term 'Invoke-WebRequest' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:18
+ Invoke-WebRequest <<<< -Uri https://stackoverflow.com/questions/20259251/powershell-script-to-check-the-status-of-a-url > tmp.txt
+ CategoryInfo : ObjectNotFound: (Invoke-WebRequest:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
$PSVersionTable
Name Value
---- -----
CLRVersion 2.0.50727.5472
BuildVersion 6.1.7601.17514
PSVersion 2.0
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
【问题讨论】:
-
究竟是什么给了你这样的输出?
-
如果你这样做会发生什么?:
Invoke-WebRequest -Uri http://mypage.global/Chemical/ -
Invoke-WebRequest 仅适用于 PowerShell 3。您要么必须升级到 PowerShell 3,要么找到其他方式来处理请求。
-
@Dangph 升级是不可能的,因为我没有管理员权限......还有什么其他方法可以实现?
标签: powershell web-services powershell-2.0 monitoring