Converting the FileSystemObject's Drive Property
Definition: Returns the drive letter of the drive on which the file resides.
Drive
You can return the drive letter given the path to the file by using the -qualifier parameter with the Split-Path cmdlet:
PS C:\scripts> Split-Path "C:\scripts\test.txt" -qualifier
C:
The FileSystemObject Drive property actually works with a reference to a file rather than the path. To replicate this in PowerShell, we use the Get-Item cmdlet to retrieve a reference to the file. We then check the FullName property to retrieve the full path to that file. After that, we pipe that path to the Split-Path cmdlet, using the -qualifier parameter to return the drive letter.
(Get-Item c:\scripts\test.txt).fullname | Split-Path -qualifier
See conversions of other FileSystemObject methods and properties.
Return to the VBScript to Windows PowerShell home page