【发布时间】:2017-06-13 13:54:11
【问题描述】:
我们公司使用Citrix,访问Citrix StoreFront有两个地址:
- internal-access.company.com
- external-access.company.com
链接 1 仅在它们位于内部网络(本地或 VPN)上时有效,链接 2 仅在它们不在内部网络上时有效。这让用户猜测他们需要双击桌面上的哪个快捷方式。
为了解决我们最终用户的困惑,我在下面编写了这个小 sn-p。它按预期工作,但因为它依赖于 PING 来查看是否可以访问内部服务器来决定......执行速度很慢。
我想做的是在收到来自 PING 的响应后立即执行相关块,而不是等待所有 4 次 PING 尝试完成。这在 PowerShell 中可行吗?
所以不是“PING 4 次,如果收到至少 1 个响应,则运行块”,而是“PING 4 次,第一次响应运行块”。
if(Test-Connection -Quiet -ComputerName "10.10.10.10" -Count 2){
$url = "http://internal-access.company.com"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
}elseif(Test-Connection -Quiet -ComputerName "8.8.8.8" -Count 4){
$url = "https://external-access.company.com"
$ie = New-Object -com internetexplorer.application;
$ie.visible = $true;
$ie.navigate($url);
}else{
$wshell = New-Object -ComObject Wscript.Shell
$wshell.Popup("Unable to connect to Citrix. Please check your network connection and call the Service Desk on +44(0)207 111 1111 if you require assistance. Thank you.",0,"No network connection detected!",0x1)
}
提前致谢, 仲裁者
【问题讨论】:
标签: powershell powershell-3.0 powershell-4.0