Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

Get ACL for File or Folder

I want to be able to dump to a string the ACL information for a file or folder, however when I run the script and it gets to the following line:-
$fileACLAccess = (Get-ACL $_.FullName).Access

Open in new window

, I just get
System.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule System.Security.AccessControl.FileSystemAccessRule

My compete code is:-
Function scanDirectory($strDirectory) {
    write-host "Snap shotting " $strDirectory
	dir $strDirectory | % { if ($_.PsIsContainer) { 
			echo "Directory Found - $_\" 
            $fileACLOwner = (Get-ACL $_.FullName).Owner
            $fileACLAccess = (Get-ACL $_.FullName).Access
            $fileACLGroup = (Get-ACL $_.FullName).Group
            
            write-host $fileACLOwner
            write-host $fileACLAccess
            write-host $fileACLGroup
            
			scanDirectory($strDirectory + "\" + $_) 
			} 
		else { 
                     $fileACLOwner = (Get-ACL $_.FullName).Owner
                     $fileACLAccess = (Get-ACL $_.FullName).Access
                     $fileACLGroup = (Get-ACL $_.FullName).Owner
			} 
		}
	}
    
scanDirectory("d:\")

Open in new window


Is it possible to get the variable to a string?

Thank you
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Function scanDirectory($strDirectory) {
    write-host "Snap shotting " $strDirectory
      dir $strDirectory | % { if ($_.PsIsContainer) {
                  echo "Directory Found - $_\"
            $fileACLOwner = (Get-ACL $_.FullName).Owner
            $fileACLAccess = (Get-ACL $_.FullName).Access
            $fileACLGroup = (Get-ACL $_.FullName).Group
           
            $fileACLOwner
            $fileACLAccess
            $fileACLGroup
           
                  scanDirectory($strDirectory + "\" + $_)
                  }
            else {
                     $fileACLOwner = (Get-ACL $_.FullName).Owner
                     $fileACLAccess = (Get-ACL $_.FullName).Access
                     $fileACLGroup = (Get-ACL $_.FullName).Owner
                  }
            }
      }
   
scanDirectory("c:\temp")