forked from ArnaudLoos/Powershell-snippets
/
NTFS_Folder_Perms.ps1
33 lines (26 loc) · 1.26 KB
/
NTFS_Folder_Perms.ps1
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
######################################################################
# Supply the root folder and the program will recurse through all the sub-folders and write the NTFS permissions to a csv
#
#
######################################################################
# VARIABLES
$ReportPath = "C:\"
$RootFolder = "c:\testperms" # This is the folder we're getting the permissions of
# Begin Program
$FolderPath = dir -Directory -Path $RootFolder -Recurse -Force
$Report = @()
$Acl = Get-Acl -Path $RootFolder
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$RootFolder;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
Foreach ($Folder in $FolderPath) {
$Acl = Get-Acl -Path $Folder.FullName
foreach ($Access in $acl.Access)
{
$Properties = [ordered]@{'FolderName'=$Folder.FullName;'AD Group or User'=$Access.IdentityReference;'Permissions'=$Access.FileSystemRights;'Inherited'=$Access.IsInherited}
$Report += New-Object -TypeName PSObject -Property $Properties
}
}
$Report | Export-Csv -path $ReportPath\FolderPermissions.csv