added prune

This commit is contained in:
Miłosz Stocki 2019-04-09 15:27:15 +02:00
parent de6b8d5643
commit d5c10979f1
Signed by: osiu97
GPG Key ID: E3D1D83FA04F51D6
2 changed files with 63 additions and 4 deletions

52
.vscode/launch.json vendored Normal file
View File

@ -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"
}
]
}

View File

@ -3,13 +3,20 @@ $WorkDir="$env:LOCALAPPDATA\ps-aclreport"
function createBaselineReport($Computer, $Share){ function createBaselineReport($Computer, $Share){
$ShareName="${Computer}-${Share}" $ShareName="${Computer}-${Share}"
$Date=(Get-Date).ToString("yyyyMMddHHmm") $Date=(Get-Date).ToString("yyyyMMddHHmmss")
$BaselineName="Baseline_${ShareName}_${Date}" $BaselineName="Baseline_${ShareName}_${Date}"
New-ACLShareReport -ComputerName $Computer -Include $Share -IncludeInherited | Export-ACLReport -Path "${Workdir}\${BaselineName}.acl" -Force New-ACLShareReport -ComputerName $Computer -Include $Share -IncludeInherited | Export-ACLReport -Path "${Workdir}\${BaselineName}.acl" -Force
} }
function pruneBaselineReports(){ 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
createBaselineReport "nas.proferis.local" "techniczny"