带通配符的PowerShell测试路径UNC
问题描述:
我试图测试一个UNC路径是否存在,但所有尝试都失败了。 此文件夹例子存在,并返回true:带通配符的PowerShell测试路径UNC
\\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*')
...除了\''*组合的许多排列组合。 但是,使用通配符时,我尝试过的任何内容都不会返回此类路径的“真”,即使它似乎可以正常工作:例如,Test-Path c:\windows\system3*
。
答
我不认为Windows支持在共享名通配符选择。
但是,如果你有足够的(远程)访问文件服务器,你可以得到的共享列表:
Get-WmiObject -class 'Win32_Share' -ComputerName 'Server'
+0
这回答了这个问题,非常感谢。 为了完整起见,这是我用来辨别'Pathx'存在的线: 'Get-WmiObject -class'Win32_Share' - 计算机名'Server'|名称类似“*路径*”' – ScriptMonkey
答
这个片段将用于映射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)"}
你的道路已经是'\\服务器\ C $ \路径*' –
[相关](https://*.com/q/35068220/1630171)。 –