diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..f3af529 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,52 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "PowerShell Launch Current File", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "args": [], + "cwd": "${file}" + }, + { + "name": "PowerShell Launch Current File in Temporary Console", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "args": [], + "cwd": "${file}", + "createTemporaryIntegratedConsole": true + }, + { + "name": "PowerShell Launch Current File w/Args Prompt", + "type": "PowerShell", + "request": "launch", + "script": "${file}", + "args": [ + "${command:SpecifyScriptArgs}" + ], + "cwd": "${file}" + }, + { + "name": "PowerShell Attach to Host Process", + "type": "PowerShell", + "request": "attach" + }, + { + "name": "PowerShell Interactive Session", + "type": "PowerShell", + "request": "launch", + "cwd": "" + }, + { + "name": "PowerShell Attach Interactive Session Runspace", + "type": "PowerShell", + "request": "attach", + "processId": "current" + } + ] +} \ No newline at end of file diff --git a/ps-aclreport.ps1 b/ps-aclreport.ps1 index 5f20144..89ca39f 100644 --- a/ps-aclreport.ps1 +++ b/ps-aclreport.ps1 @@ -3,13 +3,20 @@ $WorkDir="$env:LOCALAPPDATA\ps-aclreport" function createBaselineReport($Computer, $Share){ $ShareName="${Computer}-${Share}" - $Date=(Get-Date).ToString("yyyyMMddHHmm") + $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 + } + } + } } - -createBaselineReport "nas.proferis.local" "techniczny" \ No newline at end of file +pruneBaselineReports \ No newline at end of file