Solved

Get ACL for File or Folder

Posted on 2013-12-13
2
737 Views
Last Modified: 2013-12-13
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
0
Comment
Question by:tonelm54
2 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
Comment Utility
Access is a multivalued property.. Try to convert it to string and see if it works for you..
$fileACLAccess = (Get-ACL $_.FullName).Access | Out-String

Open in new window

0
 
LVL 18

Expert Comment

by:Raheman M. Abdul
Comment Utility
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")
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Set OWA language and time zone in Exchange for individuals, all users or per database.
This video discusses moving either the default database or any database to a new volume.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now