Using Powershell I am seeking the inverse of the drive letters currently in use.
The following code In a .bat-file reveals the currently available drives.
SETLOCAL EnableDelayedExpansion
net use
SET DRVLST=
FOR %%p IN (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO if not exist %%p:\nul @set DRVLST=!DRVLST! %%p:
echo Available Drives: %DRVLST%
echo -------------------------------------------------------------------------------
net view %SERVERNAME%
ENDLOCAL
In Powershell the drive letters in use can be extracted and stored in a variable $drives_in_use for further processing.
$drives_in_use=(Get-PSDrive).Name -match '^[a-z]$'
write-host $drives_in_use
How to obtain the result to be the 'subtraction' of $drives_in_use from all drives A to Z?
$availableDrives = $allDrives - $drives_in_use
I would assume that a reverse-lookup regex might be the solution. But I don't know how to achieve that.