I have an NTFS Audit script and would like to add a basic progress bar. At the moment I have a function that I call like normal, with $i = 100
to indicate my max %. I run through the folders via
Get-ChildItem -Path $pathToFolders -Recurse -Force | ?{ $_.PSIsContainer } | % {$counter++}
To get a total number of folders, then divide my $i
by that number to get the % increment I need to increase my progress bar by each time it evaluates a folder. Problem is it only fills the progress bar up to around 40-50% by the time the script completes? Am I missing something completely obvious?
See my code (note $j = 0
at first):
# Main
ForEach ($Folder in $Folders){
$ACLs = Get-ACL $Folder.FullName | % { $_.Access }
ForEach ($ACL in $ACLs){
$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.FileSystemRights + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
Add-Content -Value $OutInfo -Path $outputCSV
}
Write-Progress -Activity "Auditing NTFS Permissions in ${$pathToFolders}..." -Status 'Progress ->' -PercentComplete $j
$j = $j + $i
}
}