带通配符的 PowerShell 测试路径 UNC
PowerShell Test-Path UNC with a wildcard
我正在尝试测试 UNC 路径是否存在,但到目前为止所有尝试都失败了。
此文件夹示例存在,并且 returns true:
\Server\Path1
我想确认是否存在所有名称相似的文件夹,例如:
\Server\Path2
\Server\Path3 etc.
我试过在这些示例中使用通配符:
test-path "\Server\Path*"
resolve-path "\Server\Path*"
[System.IO.Directory]::Exists('\Server\Path*');
Test-Path $('filesystem::\Server\Path*')
...连同 \ " ' * 组合的许多排列。
但是,在使用通配符时,我没有尝试 returns a 'True' 这种类型的路径,即使它似乎适用于:例如 Test-Path c:\windows\system3*
。
此代码段适用于映射的 UNC 路径:
Get-PSDrive| where{$_.DisplayRoot -like "\server\test*" } | foreach{test-path -path $_.DisplayRoot}
如果您有 wmi 访问权限,则:
Get-WmiObject -Class Win32_Share -ComputerName server | where{$_.name -like "test*"} | foreach{Test-Path "\server$($_.name)"}
我认为 Windows 不支持在共享名称上选择通配符。
但是如果您有足够的(远程)访问文件服务器的权限,您可以获得共享列表:
Get-WmiObject -class 'Win32_Share' -ComputerName 'Server'
我正在尝试测试 UNC 路径是否存在,但到目前为止所有尝试都失败了。 此文件夹示例存在,并且 returns true:
\Server\Path1
我想确认是否存在所有名称相似的文件夹,例如:
\Server\Path2 \Server\Path3 etc.
我试过在这些示例中使用通配符:
test-path "\Server\Path*"
resolve-path "\Server\Path*"
[System.IO.Directory]::Exists('\Server\Path*');
Test-Path $('filesystem::\Server\Path*')
...连同 \ " ' * 组合的许多排列。
但是,在使用通配符时,我没有尝试 returns a 'True' 这种类型的路径,即使它似乎适用于:例如 Test-Path c:\windows\system3*
。
此代码段适用于映射的 UNC 路径:
Get-PSDrive| where{$_.DisplayRoot -like "\server\test*" } | foreach{test-path -path $_.DisplayRoot}
如果您有 wmi 访问权限,则:
Get-WmiObject -Class Win32_Share -ComputerName server | where{$_.name -like "test*"} | foreach{Test-Path "\server$($_.name)"}
我认为 Windows 不支持在共享名称上选择通配符。
但是如果您有足够的(远程)访问文件服务器的权限,您可以获得共享列表:
Get-WmiObject -class 'Win32_Share' -ComputerName 'Server'