Reputation: 33
I have a powershell script I've created that stores a copy of a text file to a mapped drive over a WAN VPN when the text file on the host machine is modified. It works fine until there is a brief drop in Internet connection, the VPN reconnects and is fine, but the mapped drive has a red X on it, but IS accessible when I double click on it.
The script doesn't see it as active until I've manually clicked into the red X mapped drive to 'reinstate' its availability.
I guess my question would be, what would be the best way to check if the folder is available and then store the text file there. Would it just be "oepn said folder, close and then save file"... ?
Thanks,
Upvotes: 1
Views: 39
Reputation: 61068
Try and copy the file to the folder.
If that doesn't succeed because of folder path not found (drive has a red X), try to reconnect with:
foreach($drive in (Get-SmbMapping | Where-Object { $_.Status -eq 'Unavailable' })) {
try {
New-SmbMapping -LocalPath $drive.LocalPath -RemotePath $drive.RemotePath -Persistent $true -ErrorAction Stop
}
catch {
Write-Warning "Could not (re)map $($drive.RemotePath) to $($drive.LocalPath): $($_.Exception.Message)"
}
}
Upvotes: 1