Skip to content

Instantly share code, notes, and snippets.

@gioxx
Created March 1, 2016 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gioxx/4a9becba0356d2363e80 to your computer and use it in GitHub Desktop.
Save gioxx/4a9becba0356d2363e80 to your computer and use it in GitHub Desktop.
Dump delle ACL di una cartella (con o senza ricorsività) su FS NTFS, con possibilità di passare i parametri da riga di comando (cartella da analizzare, CSV di esportazione e attivazione della ricorsività). Da lanciare direttamente su Powershell, su Domain Controller.
############################################################################################################################
# AD: NTFS DumpACL (Recursive)
#----------------------------------------------------------------------------------------------------------------
# Autore: - (modifiche: GSolone)
# URL Originale: http://www.my-powershell.com/export-backup-ntfs-permissions/
# Versione: 0.1
# Utilizzo: .\DumpACL.ps1
# (opzionale, passaggio dati da prompt) .\DumpACL.ps1 \\server\folder
# (opzionale, passaggio dati da prompt) .\DumpACL.ps1 \\server\folder -Recursive N (esclude ricorsività)
# (opzionale, passaggio dati da prompt) .\DumpACL.ps1 \\server\folder -CSV C:\temp\acl.csv
# Info: http://gioxx.org/tag/powershell
# Ultima modifica: 26-02-2016
# Modifiche: -
############################################################################################################################
#Verifica parametri da prompt
Param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[string] $Folder,
[Parameter(Position=1, Mandatory=$false, ValueFromPipeline=$true)]
[string] $Recursive,
[Parameter(Position=2, Mandatory=$false, ValueFromPipeline=$true)]
[string] $CSV
)
#Verifica CSV, se passato da prompt
if ( [string]::IsNullOrEmpty($CSV) ) {
if( (Test-Path "C:\Temp") -eq 0 ) { mkdir "C:\Temp" }
$CSV = "C:\Temp\DumpACL.csv"
Write-Host "Percorso e nome CSV non specificato, utilizzo $CSV ..." -f "Yellow"
}
#Verifico configurazione default
if ( [string]::IsNullOrEmpty($Recursive) ) {
Write-Host "Ricorsività non specificata, utilizzo default (ricorsivo) ..." -f "Yellow"
}
#Verifica ricorsività
if ( [string]::IsNullOrEmpty($Recursive) ) {
""
Write-Host "Dump ACL da: $folder (ricorsivo, salvo in $CSV)"
Get-Childitem -path "$folder" -recurse | Where-Object {$_.PSIsContainer} | Get-ACL | Select-Object Path -ExpandProperty Access | Export-CSV $CSV
} else {
""
Write-Host "Dump ACL da: $folder (NON ricorsivo, salvo in $CSV)"
if ( $Recursive -eq "n" ) { Get-Childitem -path "$folder" | Where-Object {$_.PSIsContainer} | Get-ACL | Select-Object Path -ExpandProperty Access | Export-CSV $CSV }
}
Write-Host "Done." -f "Green"
""
# Chiedo se visualizzare i risultati esportati nel file CSV
$message = "Devo aprire il file CSV $CSV ?"
$Yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", ""
$No = New-Object System.Management.Automation.Host.ChoiceDescription "&No", ""
$options = [System.Management.Automation.Host.ChoiceDescription[]]($Yes, $No)
$Excel = $host.ui.PromptForChoice("", $message, $options, 1)
if ($Excel -eq 0) { Invoke-Item $CSV }
""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment