简体   繁体   English

Powershell检测到额外的映射驱动器

[英]Powershell detecting an extra mapped drive

On a Windows PC (say "MYPC") I have multiple mapped drives; 在Windows PC(例如“ MYPC”)上,我有多个映射驱动器; according to net use : 根据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: 但是,当我在该PC上运行此Powershell时:

$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? 这些其他Z映射驱动器从何而来? 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). MYPC实际上是一台服务器,因此我不能只擦除所有​​映射的驱动器(我通常会这样做)。

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)? 如果这是由于其他用户显示了映射的驱动器而引起的,那么如何更改Powershell来缩小到仅登录用户的范围(确切地说, net use似乎在起作用)?

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 http://msdn.microsoft.com/en-us/library/windows/desktop/aa394194(v=vs.85).aspx
maybe you are running aa terminal server so check Win32_LogonSession class to get more info about the sessions id seen in providerName 也许您正在运行终端服务器,所以请检查Win32_LogonSession类以获取有关providerName中显示的会话ID的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM