Question

How to check drive is it a virtual (created using subst command)?

Get-VirtualDisk doesn't work(powershell 3.0)

Was it helpful?

Solution

You could extract the first character from each line of subst output into an array and check if a particular drive is contained in that array:

$substed = subst | % { $_.Substring(0,1) + ':' }

if ( $substed -contains 'x:' ) {
  # do stuff
}

OTHER TIPS

You can parse the result of running subst to get a listing of existing substitutions like:

$substdrives = @{};
(subst) |% { $part = $_ -split '\\: => '; $substdrives[$part[0]] = $part[1] } ;
$substdrives | ft

subst doesn't create a virtual disk, so Get-VirtualDisk won't return those drives.

You may be able to use Get-PSDrive and look for drives where the Description property matches the Description property of another drive. For example, on my system I have substed Q pointing to a path on my C drive:

>get-psdrive |where-object {$_.provider -like  "*filesystem"}|select name,description|ft -auto

Name Description
---- -----------
C    OSDisk
D
E
P
Q    OSDisk
U
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top