共享路径中的本地路径:Powershell

问题描述 投票:0回答:2

如何找到共享路径的本地路径。

我的共享路径是“ \ somemachine \ shared \ scripts \ testing”它的本地路径是“ D:\ myshares \ scripts \ testing”

谢谢!

powershell wmi unc wmi-query
2个回答
3
投票

使用WMI,您可以获得与本地路径等效的共享列表:

PS C:\> gwmi Win32_Share
Name     Path        Description
----     ----        -----------
ADMIN$   C:\Windows  Remote Admin
C$       C:\         Default share
IPC$                 Remote IPC

您只需要将Name属性与您的共享路径匹配,然后使用结果的Path属性替换它以获取该服务器上的本地路径:

$name = "shared"
$share = (gwmi Win32_Share | ? { $_.Name -eq $name }
$path = $share.Path + "\scripts\testing"

注意:您还可以将-ComputerName参数传递给gwmi cmdlet,以对另一台计算机运行该命令。您可能还需要传递-Credential参数以提供有效的凭据。


0
投票

只要您没有访问WMI的权限,也可以使用net命令来完成:

PS C:\> net share

Share name   Resource                        Remark

------------------------------------------------------------------------------
C$           C:\                             Default share
IPC$                                         Remote IPC
ADMIN$       C:\Windows                      Remote Admin
The command completed successfully.
© www.soinside.com 2019 - 2024. All rights reserved.