Export (0) Print
Expand All
Expand Minimize

Converting the FileSystemObject's Drive Property


Windows PowerShell


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

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft