Leadtheway
asked on
Excluding specific folder path in powershell
So i have this script that recursively pulls all permissions off of every folder and every drive. It works well and gets the info i need, but I was wanting to exclude several folders as to speed up the process. Is there an easy mod to this script that will help that.?
$ErrorActionPreference = "Continue"
$strComputer = $env:ComputerName
$colDrives = Get-PSDrive -PSProvider Filesystem
ForEach ($DriveLetter in $colDrives) {
$StartPath = "$DriveLetter`:\"
Get-ChildItem -LiteralPath $StartPath -Recurse |
ForEach {
$FullPath = Get-Item -LiteralPath (Get-Item -LiteralPath $_.PSPath)
(Get-Item -LiteralPath $FullPath).GetAccessControl() |
Select * -Expand Access |
Select @{N='Server Name';E={$strComputer}},
@{N='Full Path';E={$FullPath}},
@{N='Type';E={If($FullPath.PSIsContainer -eq $True) {'D'} Else {'F'}}},
@{N='Owner';E={$_.Owner}},
@{N='Trustee';E={$_.IdentityReference}},
@{N='Inherited';E={$_.IsInherited}},
@{N='Inheritance Flags';E={$_.InheritanceFlags}},
@{N='Ace Flags';E={$_.PropagationFlags}},
@{N='Ace Type';E={$_.AccessControlType}},
@{N='Access Masks';E={$_.FileSystemRights}} } |
Export-CSV -NoTypeInformation -Delimiter "|" –Path "$strComputer`_$DriveLetter.csv" }
ASKER
I'm not sure I'm understanding. I'm still getting used to powershell so sometimes i struggle getting fancy..lol
ASKER
or is there a way i could import a CSV of the folder paths I want to run against?
-Exclude for Get-ChildItem should do exactly that - exclude partitial matches of the path name.
This
This
$FullPath = Get-Item -LiteralPath (Get-Item -LiteralPath $_.PSPath)
(Get-Item -LiteralPath $FullPath).GetAccessControl() |
is much too much. $_ already contains the item, so it should just be ($_.GetAccessControl() |
If you want to use a positive list, does it only contain the folder name, or the path?
ASKER
i could do either, which would be easier?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can either define each "path" to exclude individually with if statements or you can make an array that you'd like to exclude.