Equivalent of net use (to list computer's connections) in powershell?

痴心易碎 提交于 2019-12-22 04:42:39

问题


According to windows help NET USE, when used without options, lists the computer's connections.

I'd like to find a way in powershell to get a list of the Remote entries in net use's output.

I know that as an extreme measure I can parse the result of the "net use" command itself, but I'd rather not rely on the text output of that command.

Can anybody help me out? thank you

Michele

Status       Local     Remote                    Network  
-------------------------------------------------------------------------------  
OK                     \\SERVER02\example          Microsoft Windows Network  
OK                     \\SERVER02\prova            Microsoft Windows Network  
Disconnected           \\SERVER03\test             Microsoft Windows Network  
OK                     \\SERVER02\remoteshare      Microsoft Windows Network  
Disconnected           \\SERVER03\remoteshare   

回答1:


For the mapped logical drive you can use WMI class Win32_MappedLogicalDisk :

Get-WmiObject Win32_MappedLogicalDisk

Here is another way with Win32_LogicalDisk :

PS C:\> Get-WmiObject -Query "Select * From Win32_LogicalDisk Where DriveType = 4"

DeviceID     : V:
DriveType    : 4
ProviderName : \\jpbdellf1\c$
FreeSpace    :
Size         :
VolumeName   :

Edited

You are right, you can get what you need with Win32_NetworkConnection :

PS > Get-WmiObject Win32_NetworkConnection

LocalName                     RemoteName                    ConnectionState               Status
---------                     ----------                    ---------------               ------
                              \\jpbasusf1\temp              Connected                     OK

On Seven or W2K8 be careful to call this with the same user that run the NET USE because it's a session information.



来源:https://stackoverflow.com/questions/8083014/equivalent-of-net-use-to-list-computers-connections-in-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!