22 lines
1006 B
PowerShell
22 lines
1006 B
PowerShell
Import-Module ACLReportTools
|
|
$WorkDir="$env:LOCALAPPDATA\ps-aclreport"
|
|
|
|
function createBaselineReport($Computer, $Share){
|
|
$ShareName="${Computer}-${Share}"
|
|
$Date=(Get-Date).ToString("yyyyMMddHHmmss")
|
|
$BaselineName="Baseline_${ShareName}_${Date}"
|
|
New-ACLShareReport -ComputerName $Computer -Include $Share -IncludeInherited | Export-ACLReport -Path "${Workdir}\${BaselineName}.acl" -Force
|
|
}
|
|
|
|
function pruneBaselineReports(){
|
|
$reg="([a-zA-Z]+_.*)_\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}\.acl"
|
|
$ReportGroups=(Get-Childitem -Path $WorkDir) | Sort-Object -Property Name | Where-Object {$_.name -match "([a-zA-Z]+_.*)_\d{4}\d{2}\d{2}\d{2}\d{2}\d{2}\.acl"} | Group-Object -Property {$Matches[1]}
|
|
For ($i=0; $i -lt $ReportGroups.Length; $i++){
|
|
For ($j=0; $j -lt $ReportGroups[$i].Count; $j++){
|
|
if ($j -ne 0 -And $j -ne ($ReportGroups[$i].Count-1)){
|
|
remove-item $ReportGroups[$i].Group[$j].FullName -Force
|
|
}
|
|
}
|
|
}
|
|
}
|
|
pruneBaselineReports |