Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

Converting the Windows Script Host EnumNetworkDrives Method

Windows PowerShell

Definition: Returns the current network drive mapping information.


Need a list of all the mapped drives on a computer? That information can be retrieved using the Get-WMIObject cmdlet and the Win32_LogicalDisk class. In the following command, we use Get-WMIObject and the –query parameter to retrieve all instances of the Win32_LogicalDisk class where the DriveType property is equal to 4; as you probably figured out, any drive with a DriveType of 4 is a mapped network drive. After retrieving the collection of mapped network drives we then use Select-Object to filter out all the returned information except for the DeviceID and ProviderName properties; that’s done to provide parity with Windows Script Host and the EnumNetworkDrives method.

The command itself looks like this:

Get-WMIObject -query "Select * From Win32_LogicalDisk Where DriveType = 4" | Select-Object DeviceID, ProviderName

And the output will look similar to this:

DeviceID                                    ProviderName
--------                                    ------------
M:                                          \\atl-fs-001\Users
X:                                          \\atl-ws-007\Public

Incidentally, you can also use Get-WMIObject to return drive mapping information for a remote computer. To do that, simply add the –computername property followed by the name of the remote machine:

Get-WMIObject -computername atl-ws-001 -query "Select * From Win32_LogicalDisk Where DriveType = 4" | 
Select-Object DeviceID, ProviderName

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

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