I would like to mapping a network. I need to use retry if the mapping fail. After maximum retry it will fail out and continue to another process. If the mapping pass, then continue to another process too. I've tried this way, but seems the retry is not working. Once the mapping fail, it does not do the network mapping process, only process the looping. Anyone can give me idea please.
$Stoploop = $false
[int]$Retrycount = "0"
do {
try {
$net = New-Object -ComObject WScript.Network
$net.MapNetworkDrive("$Path", "\\$IP\$Folder", $False, "$Server\$user", "$pass")
$Message = "NetWork Mapping : " + $Path + " Mount Successful"
Write-Host $Message
$Stoploop = $true
CaptureLog "$Message`n "
}
catch {
if ($Retrycount -eq 15){
$Message_1 = "Could not mount after 15 retries." + " $_"
$Stoploop = $true
CaptureLog $Message_1
ErrorHandling $Message_1
}
else {
$Message = "NetWork Mapping : " + $Path + " Trying to mount..."
Write-Host $Message
CaptureLog $Message
Start-Sleep -Seconds 3
$Retrycount = $Retrycount + 1
}
}
}
while ($Stoploop -eq $false) {
}
Thank you so much for the advice. Appreciated!