On a Windows PC (say “MYPC”) I have multiple mapped drives; according to net use:
>net use
New connections will be remembered.
Status Local Remote Network
-------------------------------------------------------------------------------
OK X: \\BLAHBLAH1\e$ Microsoft Windows Network
OK Y: \\BLAHBLAH2\e$ Microsoft Windows Network
OK Z: \\BLAHBLAH3\s$ Microsoft Windows Network
The command completed successfully.
But when I run this Powershell on that PC:
$disks = Get-WmiObject -Class Win32_MappedLogicalDisk -Filter "DeviceID='Z:'"
foreach($disk in $disks)
{
[Console]::WriteLine("DEBUG: " + $disk.Name + " is " + $disk.ProviderName );
}
It returns:
DEBUG: \\MYPC\root\cimv2:Win32_MappedLogicalDisk.DeviceID="Z:",SessionID="4491554321" is \\OTHERPC\c$\
DEBUG: \\MYPC\root\cimv2:Win32_MappedLogicalDisk.DeviceID="Z:",SessionID="3129225404" is \\BLAHBLAH3\s$
DEBUG: \\MYPC\root\cimv2:Win32_MappedLogicalDisk.DeviceID="Z:",SessionID="5884378361" is \\BLAHBLAH3\s$
Where did these other Z mapped drives come from? How do they occupy the same drive letter? Can I tell if they’re safe to remove, and if so how?
MYPC is actually a server, so I cannot just wipe out all mapped drives (I would do that normally).
If this is due to mapped drives showing up from other users, how can I change the Powershell to narrow down to only the logged-in user (exactly how net use seems to act)?
did you try to test the availability or status properties of the device?
this can result with net drive used by locally logged on user see the remarks at bottom of
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394194(v=vs.85).aspx
maybe you are running a a terminal server so check Win32_LogonSession class to get more info about the sessions id seen in providerName