I've check other posts and even following those I can't get this to function.
I'm trying to pull all of the ACL information from a drive but exclude the Windows folder.
This is the code I'm using, but it always tries to include the folder. Can someone tell me why this isn't working?
I've also tried Where-Object.
$containers = Get-ChildItem -Path $Path -Recurse -Exclude $exclude |
? {$_.FullName -notmatch '\\windows\\?'}
Main Code:
function Get-PathPermissions {
param ( [Parameter(Mandatory=$true)] [System.String]${Path} )
begin {
$root = Get-Item $Path
($root | Get-Acl).Access |
Add-Member -MemberType NoteProperty -Name "Path" -Value $($root.fullname).ToString() -PassThru
}
process {
$exclude = @('C:\Windows\*')
$containers = Get-ChildItem -Path $Path -Recurse -Exclude $exclude |
? {$_.psIscontainer -eq $true}
if ($containers -eq $null) {break}
foreach ($container in $containers)
{
(Get-Acl $container.FullName).Access |
? { $_.IsInherited -eq $false } |
Add-Member -MemberType NoteProperty -Name "Path" -Value $($container.fullname).ToString() -PassThru
}
}
}
Get-PathPermissions $args[0]
Filtering with
-notmatch '\\windows\\?'should work. I'd use the full path, though, to avoid potential undesired exclusions:On PowerShell v3 or newer you can also use the
-Directoryswitch for restricting the results to directories: