1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| # FONCTIONS #
# Fenêtre de sélection dossier
function Select-Folder($message='Select a folder', $path = 0) {
$object = New-Object -comObject Shell.Application
$folder = $object.BrowseForFolder(0, $message, 0, $path)
if ($folder -ne $null) {
$folder.self.Path
}
}
# MAIN #
# Effacer page #
clear
# Création du fichier Excel avec les entêtes #
$a = New-Object -comobject Excel.Application
$a.Visible = $True
$b = $a.Workbooks.Add()
$d = $b.Worksheets.Item(1)
$d.name = "Droits NTFS"
$ligne=1
$col=1
$d.Cells.Item($ligne,$col)= "Fullname"
$col++
$d.Cells.Item($ligne,$col)= "Identity"
$col++
$d.Cells.Item($ligne,$col)= "Rights"
$col++
$d.Cells.Item($ligne,$col)= "IsInherited"
$Ligne++
# Sélectionner un dossier de recherche #
$RootPath = Select-Folder
# Pareser les répertoires et sous répertoires #
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true}
foreach ($Folder in $Folders)
{
$ACL = Get-Acl $Folder.Fullname
foreach($acl in $acl)
{
$path = $acl.path
$owner = $ACL.owner
$access = $acl.Access
foreach($access in $access)
{
$Col=1
$d.Cells.Item($ligne,$col)= $Folder.Fullname -replace "\r\n","" #répertoire#
$Col++
$d.Cells.Item($ligne,$col)= $access.IdentityReference.Value -replace "\r\n","" #groupe#
$Col++
$ObjRow = out-string -InputObject $access.FileSystemRights #Accès NTFS#
$d.Cells.Item($ligne,$col)= $ObjRow -replace "\r\n",""
$Col++
$ObjRow = out-string -InputObject $access.IsInherited #Héritage : Yes/no#
$d.Cells.Item($ligne,$col)= $ObjRow -replace "\r\n",""
$ligne++
}
}
}
# Message box : fin de traitement#
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$oReturn=[System.Windows.Forms.Messagebox]::Show("Traitement termine")
$Resize=$d.UsedRange
$Resize.EntireColumn.AutoFilter()
$Resize.EntireColumn.AutoFit()
$b.SaveAs("D:\Bureau\NTFS.xlsx")
$a.Quit() |
Partager