1

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,

asked Dec 19, 2024 at 11:04

1 Answer 1

1

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)"
 }
}
answered Dec 19, 2024 at 12:06
Sign up to request clarification or add additional context in comments.

2 Comments

thank you, it worked a treat!
@UniqueTurbo Thanks for the nice feedback. Perhaps you would consider accepting the answer so others with a similar question can find it more easily

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.