How to Get NTFS Access Permissions via PowerShell

That’s a fantastic PowerShell script that helps you to find out and export the permissions to a file with csv format. It takes time to get the result according to your data size. I needed such a script to get information that which user or which group has an access to a folder or which folders has inheritance or not.

$OutFile = "C:\NTFSPermissions.csv" #Output file location
$Header = "Folder Path,IdentityReference,AccessControlType,IsInherited,InheritanceFlags,PropagationFlags"
$FileExist = Test-Path $OutFile 
If ($FileExist -eq $True) {Del $OutFile} 
Add-Content -Value $Header -Path $OutFile 
$RootPath = "\\server\sharedfolder\" #share path
$Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} 
		foreach ($Folder in $Folders){
		$ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access  }
		Foreach ($ACL in $ACLs){
		$OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference  + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags
		Add-Content -Value $OutInfo -Path $OutFile 
}}

The only problem is the file path. You will get errors if file path longer than 255 characters, but it doesn’t affect process. If you work on a domain environment you have to run this script on domain controller.

Thanks for your time reading

Regards,

Hasan

Published by Hasan Altin

I don't see any difference between the one who doesn't share its knowledge or the one who doesn't share its bread.

Leave a Reply

Your email address will not be published.