3

I'd like to use WMI to retrieve all logical disks from a remote host. For some unknown reason, running get-wmiobject Win32_LogicalDisk -computername remoteHost fails to include network drives located on the remote Windows host. However, running get-wmiobject Win32_LogicalDisk locally on remoteHost successfully retrieves all logical disks, network drives included.

For example, running the command locally retrieves all logical disks (output formatted for clarity):

>get-wmiobject Win32_LogicalDisk

DeviceID     : A:
DriveType    : 2

DeviceID     : C:
DriveType    : 3

DeviceID     : D:
DriveType    : 5

DeviceID     : S:   // this is a network drive
DriveType    : 4
ProviderName : \\path\Share

However, running the same command remotely fails to retrieve network drive S:

>get-wmiobject Win32_LogicalDisk -computername remoteHost -credential DOMAIN\Admin

DeviceID     : A:
DriveType    : 2

DeviceID     : C:
DriveType    : 3

DeviceID     : D:
DriveType    : 5

The same happens if I use WinRM. The remote host is running Win Server 2012 R2. The result is the same no matter what OS I run the command on (Win7, Win Server 2008 R2, Win Server 2012 R2).

Any ideas what may be causing the network drive(s) to be omitted from the result set?

  • Drive maps exist within the context of a specific user session. Which user account account mapped the S drive? Are you providing the same credentials to run the remote WMI command? You may need to modify WMI security (remote read) for non admins if that user is not an admin. – Clayton Sep 21 '15 at 15:07
  • Yes, I'm providing the same credentials (admin in all cases). – w128 Sep 22 '15 at 8:00
2

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.

| improve this answer | |
  • This doesn't work on remote hosts properly. – NetMage Feb 10 '17 at 22:59
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.

| improve this answer | |
  • Welcome to the site. Thanks for the contribution. I edited your answer a bit and fixed some syntax errors. Have a look to ensure I didn't change the spirit of your response. Cheers! – Citizen Jun 17 '16 at 8:44
0

even this works

Get-WmiObject -Class Win32_logicaldisk  -Filter DriveType=4
| improve this answer | |
  • Doesn't work on remote computers - returns the wrong DriveType and doesn't return any path information. – NetMage Feb 10 '17 at 22:58
0

According to this information enmimaquinafunciona: Ver todas las unidades mapeadas (view network drives) the Power Shell command: Get-WmiObject "Win32_MappedLogicalDisk" as well as the cmd > net use should work for this purpose, however they are not available nor returning any information since Windows Vista.

  1. There is a workaround reading directly the registry key from Power Shell:

Get-ChildItem Registry::HKEY_CURRENT_USER\Network\*

  1. If you can edit the registry, there is a posible solution: In HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System Create a DWORD named EnableLinkedConnections and set its value to 1. You'll have to restart the computer.

Having that key created, it is possible to use both commands Get-WmiObject and net use in Power Shell, and Windows Command Prompt respectively.

It worked for me in a Windows 10 machine.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.