【发布时间】:2021-12-21 03:34:09
【问题描述】:
我想映射网络。如果映射失败,我需要使用重试,最大重试5次。我已经尝试过这种方式,但我无法弄清楚如何添加最大重试次数。
Do{
Try{
$net = new-object -ComObject WScript.Network
$net.MapNetworkDrive("$Directory", "\\IP\$Folder", $False, "$Server\$SQL", "$pass")
$Message = "Mapping : " + $Directory + "Successful"
Write-Host $Message
}
Catch{
$Message= "Mapping : " + $Directory + " Fault" + " $_"
Write-Host $Message
# in here there is error handling.
CallErrorHandlingFunction
}
}While($? -ne $true)
# in here there is next process after network mapping succesfull.
CallNextProcess
任何人都可以提供帮助,非常感谢。谢谢
【问题讨论】:
标签: powershell loops network-drive retry-logic