嘿伙计们
我有一个powershell脚本,这是工作正常,但我想扩大它与另一行。这是我有的。
$Path = "\\xyz\trigger1.txt"
$Path2 = "$env:userprofile\xyz\trigger2.txt"
if ((Test-Path $Path -PathType Leaf) -and (-not(Test-Path $Path2 -PathType Leaf))){
if((get-process "XXX" -ea SilentlyContinue) -eq $Null)
{
"not Running"
copy-item "\\xyz\xyz\*" "$env:userprofile\def\" -recurse -ErrorAction SilentlyContinue
start-sleep -s 5
}
else
{
"running"
stop-process -name "XXX" -force
start-sleep -s 5
copy-item "\\xyz\xyz\*" "$env:userprofile\def\" -recurse -ErrorAction SilentlyContinue
start-sleep -s 5
}
}
else
{
start-sleep -s 5
}
现在我想用一个函数来扩展这个脚本,首先检查服务器是否可用。如果不是,则应使用永久测试连接,直到其可用为止。当服务器可用时,脚本应该继续运行。
2条答案
按热度按时间8e2ybdfx1#
你可以试试这个:
只有当不发生ResourceUnavailable类型的错误时,脚本才会退出此循环。
5jvtdoz22#
使用Test-Connection和-Quiet选项将返回true或false: