powershell - 获取网络使用详细信息
问题描述
我正在使用net use
获取 Windows 安装路径和驱动器。
PS C:\Users\jagg> 网络使用 将记住新的连接。 状态 本地 远程 网络 -------------------------------------------------- ----------------------------------------- OK Y: \\ITHANSJJA001.ABC.COM\opmas$ 微软视窗网络 命令成功完成。
我想使用 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
}
}
希望有帮助,
李
推荐阅读
- rest - 带有正文 VS POST 的 GET 请求,用于检索大型资源
- java - id "" 未在 Android Studio 中的任何地方定义
- android - cmake - 为 iOS、模拟器和 Android 链接一个预编译库
- python - 气流:并行链接任务
- google-apps-script - 在对象中存储一个数组并将其传递给 Code.gs 函数。给出参考错误
- git - 如何从 git 历史记录和 git 对象中完全删除文件
- java - 为什么我的 java 代码一开始就这么早就结束了?
- firebase - 让我的 Firebase 应用程序专门触发微服务
- razor - 是否可以更改每个 Razor 组件的 RenderMode?
- javascript - 在 Ace 编辑器中隐藏行