windows 相当于powershell中的网络使用(列出计算机的连接)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8083014/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:26:42  来源:igfitidea点击:

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

windowspowershellnet-use

提问by mic.sca

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

根据windows help NET USE,当不带选项使用时,列出计算机的连接。

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

我想在 powershell 中找到一种方法来获取 net use 输出中的 Remote 条目列表。

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.

我知道作为一种极端措施,我可以解析“net use”命令本身的结果,但我宁愿不依赖该命令的文本输出。

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   

回答by JPBlanc

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

对于映射的逻辑驱动器,您可以使用 WMI 类Win32_MappedLogicalDisk

Get-WmiObject Win32_MappedLogicalDisk

Here is another way with Win32_LogicalDisk:

这是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:

你是对的,你可以通过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.

在 7 或 W2K8 上小心使用运行 NET USE 的同一用户调用它,因为它是会话信息。