0

I'm trying to test if a UNC path exists, but all attempts have failed so far. This folder example exists, and returns true:

\\Server\Path1

I'd like to confirm all folders with similar names exist, such as:

\\Server\Path2 
\\Server\Path3 etc.

I've tried using a wildcard in these examples:

test-path "\\Server\Path*"
resolve-path "\\Server\Path*"
[System.IO.Directory]::Exists('\\Server\Path*');
Test-Path $('filesystem::\\Server\Path*')

...Along with many permutations of the \ " ' * combination. However, nothing I've tried returns a 'True' for this type of path when using a wildcard, even though it seems to work fine for: Test-Path c:\windows\system3* for example.

ScriptMonkey
  • 191
  • 1
  • 3
  • 20

2 Answers2

1

This snippet will work for mapped UNC paths :

   Get-PSDrive| where{$_.DisplayRoot -like "\\server\test*" } | foreach{test-path -path $_.DisplayRoot}

If you have wmi access ,then :

Get-WmiObject -Class Win32_Share -ComputerName server | where{$_.name -like "test*"} | foreach{Test-Path "\\server\$($_.name)"}
ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17
1

I don't think Windows supports wildcard selection on share names.

But if you have sufficient (remote) access to the file server you can get a list of shares:

Get-WmiObject -class 'Win32_Share' -ComputerName 'Server'
Richard
  • 106,783
  • 21
  • 203
  • 265
  • That's answered the question, thanks very much. For completeness, this is the line I've used to discern the existence of 'Pathx': `Get-WmiObject -class 'Win32_Share' -ComputerName 'Server' | where Name -Like "*Path*"` – ScriptMonkey Aug 31 '17 at 00:43