I have the following permissions: 2.0 script:
function getFreeDrive { [char[]]$driveLetters = @([char]'E'..[char]'Z') foreach ($d in $driveLetters) { if(!(Test-Path -Path "$d`:" -IsValid)) { return $d } } } $drive = getFreeDrive subst "$drive`:" T:\temp ls "$drive`:\" # just a dummy command subst "$drive`:" /D
I want a script
- find the first unused drive letter
- create a new disk using subst
- do something on this disc.
- delete the disk with subst
The script works fine when I run it the first time. If I run the script a second time in the same shell, I get an error message from the ls command saying that the drive was not found. If I open a new shell and run the script, it works fine again.
What is the problem with my script and how can I make it work several times in the same powershell instance?
Or maybe there is an alternative to subst ? I tried using the powershell drive, but it does not work with other Windows programs (for example, devenv.exe).
guini source share