【发布时间】:2014-11-04 15:36:49
【问题描述】:
如何找到共享路径的本地路径。
我的共享路径是\\somemachine\shared\scripts\testing
它的本地路径是D:\myshares\scripts\testing
谢谢!
【问题讨论】:
标签: powershell wmi unc wmi-query
如何找到共享路径的本地路径。
我的共享路径是\\somemachine\shared\scripts\testing
它的本地路径是D:\myshares\scripts\testing
谢谢!
【问题讨论】:
标签: powershell wmi unc wmi-query
使用 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 参数以提供有效凭据。
【讨论】:
-ComputerName 时Path 为空(并且远程计算机是Windows Server)
万一您无权访问 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.
【讨论】: