Windows 10 Error handling in Powershell

eager2learn

Honorable Member
Joined
Mar 27, 2017
Messages
7
A Windows system use an external drive N:.
A programs that use the external drive give sometimes an error message like "Directory N:\datastore is not available".

To test the continuous availability I write the next batch script.

:loop
@TimE /t >> N:\datastore\test_times.txt
@sleep 30
@goto loop

During the night this script stops in cmd.exe with the message: "The system cannot open the device or file specified".
It is intended that this script continues as soon as the disk is available again.
Is it possible to make such a batch script (maybe in powershell) that don't stop, but continues as soon as the disk is available again?
 
Solution
In Powershell it would just be
Code:
While(-not(Test-Path N:\))
{
    Start-Sleep -Seconds 30
}
# Continue the rest of the script when drive N: is available
In Powershell it would just be
Code:
While(-not(Test-Path N:\))
{
    Start-Sleep -Seconds 30
}
# Continue the rest of the script when drive N: is available
 
Solution
I know cmd.exe and I know Linux bash very well, but Powershell is new for me.
I get in Powershell the next error message
'while' is not recognozed as an internal or external command, operable program or batch file.
and the same error message for "{"