代码之家  ›  专栏  ›  技术社区  ›  ScriptMonkey x0n

带有通配符的PowerShell测试路径UNC

  •  0
  • ScriptMonkey x0n  · 技术社区  · 7 年前

    此文件夹示例存在,并返回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*')
    

    ...以及\“'*组合的许多排列。 Test-Path c:\windows\system3* 例如

    2 回复  |  直到 7 年前
        1
  •  1
  •   Richard    7 年前

    但是,如果您有足够的(远程)文件服务器访问权限,则可以获得共享列表:

    Get-WmiObject -class 'Win32_Share' -ComputerName 'Server'
    
        2
  •  1
  •   ClumsyPuffin    7 年前

       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)"}