Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Converting the Windows Script Host EnumNetworkDrives Method


Windows PowerShell


Definition: Returns the current network drive mapping information.

EnumNetworkDrives


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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.