Win32_LogicalDisk doesn't retrieve network drives from remote machines

Solution 1:

Turns out using Win32_MappedLogicalDisk will specifically retrieve network drives even from remote hosts.

Disclaimer: I don't guarantee that this solution is the best (or even accurate) way to resolve this problem, nor do I know if there are any additional considerations involved; it merely solves my specific problem.

Solution 2:

As far as I have researched, there are 2 places Windows stores networks drives (Map drives, if you exclude PS-drives).

  • One is WMI, as mentioned here, you can get this information in WMI Win32_MappedLogicalDisk class.

  • Two is registry, under HKEY_Current_User:\Network All the keys here, is network letters and map drive information.

An ex. on a key is:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Network\x]
"RemotePath"="\\\\Server1\\ShareName"
"UserName"=dword:00000000
"ProviderName"="Microsoft Windows Network"
"ProviderType"=dword:00020000
"ConnectionType"=dword:00000001
"DeferFlags"=dword:00000004

Powershell Code

To the get the Mapdrive information:Get-ItemProperty -Path "HKCU:\Network\*"

You can not get this information in your logon user context. This information is stored in another users context and that is not accessible to you. I cannot go any further in to this here, as this is a LARGE topic in Powershell or for that matter .Net.

To get this information from the Registry and WMI, you will need to run the code in the users context. You can get the Credential for the user, you can create a GPO, that runs in the logged on users context or you can use System Center to run the code in the "Log on users" context.

Hope this is useful information. It took some time for me to learn and dig up.

Tags:

Wmi

Winrm