首页 > 解决方案 > 获取网络使用详细信息

问题描述

我正在使用net use获取 Windows 安装路径和驱动器。

PS C:\Users\jagg> 网络使用
将记住新的连接。


状态 本地 远程 网络
-------------------------------------------------- -----------------------------------------
OK Y: \\ITHANSJJA001.ABC.COM\opmas$
                                                微软视窗网络
命令成功完成。

我想使用 PowerShell 命令获取驱动器和安装路径详细信息。有没有办法只使用 PowerShell 来获取它?

标签: powershell

解决方案


您似乎对 powershell 能够做什么感到困惑。[咧嘴笑]

但是,这里有两种方法可以获取您想要的信息。第一个解析net use第二个用于Get-PSDrive本地获取相同信息的输出。

(net use) -replace '\s{2,}', ',' |
    Select-String -SimpleMatch '\\' |
    ConvertFrom-Csv -Header 'Status', 'DriveLetter', 'MountPath', 'Network' |
    Select-Object -Property DriveLetter, MountPath

''

Get-PSDrive -PSProvider FileSystem |
    # the 4 slashes are 2 regex-escaped slashes
    Where-Object {$_.DisplayRoot -match '\\\\'} |
    ForEach-Object {
        [PSCustomObject]@{
            DriveLetter = '{0}:' -f $_.Name
            MountPath = $_.DisplayRoot
            }
        }

希望有帮助,


推荐阅读