I am trying to check ACLs on UNC paths via the Get-Acl
cmdlet.
The below works fine when browsing the local filesystem or on a UNC path without spaces.
$ou = 'OU=Security Groups,DC=mydomain,DC=local'
$basepath = '\\mydomain\dfsroot'
$filter = '*501*'
Get-ADGroup -SearchBase $ou -Filter { Name -like $filter } | % {
$principle = $_.samAccountName
Get-ChildItem -LiteralPath $basepath -Recurse | % {
$path = $_.FullName
($path | Get-Acl).Access.IdentityReference | % { if ( $_.Value -match $principle ) { Write-Host "$principle has rights to $path" }}
}
}
On UNC paths with spaces I get a "FileNotFoundException":
Get-Acl : \local501\dfsroot\docs\Accounting\Bankruptcy Files\NOTICE TO MEMBERSHIP RE-CHAPTER 11.pdf
At C:\Users\administrator.LOCAL501\Documents\IT Support Guys - (855) 4 IT GUYS\Files\find_paths_by_principle.ps1:11 char:18
+ ($path | Get-Acl).Access.IdentityReference | % { if ( $_.Valu ...
+ ~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Acl],FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException,Microsoft.PowerShell.Commands.GetAclCommand
Can somebody help me understand what's going on here?
Thanks!