Hi Everyone,
I need to exclude the certain pattern result of the below script to export the Explicitly defined ACL that is already working.
Script:
$Excludes = 'NT AUTHORITY\SYSTEM', 'BUILTIN\Administrators', 'CREATOR OWNER', 'Everyone', 'S-1-5-21' $reExcludeObjects = '^({0})$' -f (($Excludes | ForEach-Object { [regex]::Escape($_) }) -join '|') function Get-CustomDirInfo([IO.DirectoryInfo]$path, $parentAcl) { $containerInherit = [Security.AccessControl.InheritanceFlags]::ContainerInherit $acl = (Get-Acl -Path $path.FullName).Access | Foreach-Object { New-Object PSObject -Property @{ Path = $path.FullName; IdentityReference = $_.IdentityReference; FileSystemRights = $_.FileSystemRights; IsInherited = $_.IsInherited; InheritanceFlags = $_.InheritanceFlags; InheritedFrom = if ($_.IsInherited) { if ($parentAcl) { $current = $_ $parentAce = $parentAcl | Where-Object { ($current.IdentityReference -eq $_.IdentityReference) -and ($current.FileSystemRights -band $_.FileSystemRights) -and ($_.InheritanceFlags -band $containerInherit) -and ($_.IdentityReference -notmatch $reExcludeObjects) } if (!$parentAce -or ($parentAce.count -gt 1)) { Write-Warning "Something is not right Parent ACE Count = $($parentAce.count) - $($path.FullName)" #Export the broken direcotries path as unique entries $BrokenACLDirectories += $path.FullName $BrokenACLDirectories | Select-Object -exp FullName -Unique | OGV -Title "There are $($BrokenACLDirectories.Count) Broken Directories" } if ($parentAce.IsInherited) { $parentAce.InheritedFrom } else { Split-Path $path.FullName -Parent } } else { "Unknown (Top:$($path.FullName))" } } else { "Not Inherited" } } } $acl $inheritableAcl = $acl | Where-Object { $_.InheritanceFlags -band $containerInherit } $path.FullName | Get-ChildItem | Where-Object { $_.PsIsContainer } | Foreach-Object { Get-CustomDirInfo $_ $inheritableAcl } } Get-CustomDirInfo (Get-Item F:\FileShare\Corporate) | ft Path, IdentityReference, FileSystemRights, IsInherited, InheritedFrom -Auto
However, even with the above script RegEx filtering, the result is still the same?
Also in Line #28, the OGV is not showing the unique directory which is throwing error:
Select-Object : Property "FullName" cannot be found. At line:30 char:49 + ... $BrokenACLDirectories | Select-Object -exp FullName -Unique | OGV - ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (F:\FileShare\Shared-Dir\W3SVC71:PSObject) [Select-Object], PSArgumentException + FullyQualifiedErrorId : ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand
Thank you in advance,