powershell - Get-ChildItem Recursive Exclude NOT Excluding Folder -


i've check other posts , following can't function.

i'm trying pull of acl information drive exclude windows folder.

this code i'm using, tries include folder. can tell me why isn't working?

i've 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 -notmatch '\\windows\\?' should work. i'd use full path, though, avoid potential undesired exclusions:

$containers = get-childitem -path $path -recurse |               ? { $_.fullname -notmatch '^c:\\windows\\?' -and $_.psiscontainer} 

on powershell v3 or newer can use -directory switch restricting results directories:

$containers = get-childitem -path $path -recurse -directory |               ? { $_.fullname -notmatch '^c:\\windows\\?' } 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

Kivy: Swiping (Carousel & ScreenManager) -