来自共享路径的本地路径:Powershell

Pra*_*aja 2 powershell wmi unc wmi-query

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

我的共享路径是 \\somemachine\shared\scripts\testing

它的本地路径是 D:\myshares\scripts\testing

谢谢!

Goy*_*uix 5

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

PS C:\> gwmi Win32_Share
Name     Path        Description
----     ----        -----------
ADMIN$   C:\Windows  Remote Admin
C$       C:\         Default share
IPC$                 Remote IPC
Run Code Online (Sandbox Code Playgroud)

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

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

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