How to check drive is it virtual, Powershell

560 views Asked by At

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

Get-VirtualDisk doesn't work(powershell 3.0)

3

There are 3 answers

0
Ansgar Wiechers On BEST ANSWER

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
}
0
RickH On

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
2
alroc On

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