Converting the FileSystemObject's GetDrive Method

Definition: Returns an instance of the Drive object associated with the given path.

GetDrive

The most reliable way to do this in PowerShell is to use the .NET Framework object System.IO.DriveInfo to retrieve information about a particular drive.

$d = New-Object -typename System.IO.DriveInfo -argumentlist "C:"
$d

This doesn’t work with network shares (i.e., \\atl-fs-01\scripts), it works only with mapped drive letters.

You can retrieve drive properties from all drives, including PowerShell drives such as registry drives, by using the Get-PSDrive cmdlet.

Get information about all drives:

Get-PSDrive

Get information about the C: drive:

Get-PSDrive c

You can retrieve a list of all the actual drives (not including PowerShell drives) on the computer by once again using the .NET Framework:

[System.IO.DriveInfo]::GetDrives()

See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page