I would like to mapping the network. I need to use retry if the mapping fail, and the maximum retry 5 times. I've tried this way, but I can't figure out how to add the maximum retry.
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
Anyone can help really appreciated. Thanks