问题描述
根据windows help NET USE,当不带选项使用时,列出计算机的连接.
According to windows help NET USE, when used without options, lists the computer's connections.
我想在 powershell 中找到一种方法来获取 net use 输出中的 Remote 条目列表.
I'd like to find a way in powershell to get a list of the Remote entries in net use's output.
我知道作为一种极端措施,我可以解析net use"命令本身的结果,但我宁愿不依赖该命令的文本输出.
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.
有人可以帮我吗?谢谢
米歇尔
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
推荐答案
对于映射的逻辑驱动器,您可以使用 WMI 类 Win32_MappedLogicalDisk :
For the mapped logical drive you can use WMI class Win32_MappedLogicalDisk :
Get-WmiObject Win32_MappedLogicalDisk
PS C:\> Get-WmiObject -Query "Select * From Win32_LogicalDisk Where DriveType = 4"
DeviceID : V:
DriveType : 4
ProviderName : \\jpbdellf1\c$
FreeSpace :
Size :
VolumeName :
已编辑
你说得对,你可以通过 Win32_NetworkConnection :
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
在 7 或 W2K8 上,请小心使用运行 NET USE 的同一用户调用它,因为这是会话信息.
On Seven or W2K8 be careful to call this with the same user that run the NET USE because it's a session information.
这篇关于相当于powershell中的网络使用(列出计算机的连接)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!