header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Simple ACL script
Last Post 01 Sep 2008 10:21 PM by halr9000. 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
edroszczUser is Offline
New Member
New Member
Posts:1

--
01 Sep 2008 09:26 PM  

Hi!

I just started to learn PoweShell and I havn't really done any scripting prior to this. So far I am just trying to learn general PowerShell syntax, how to work with objects...

I created a script that will search your current folder and all subfolders for files. And for each file it finds it will print the path + filename, the owner of the file and the ACL of the file. I guess the script works but my question is, is this an efficient way to accomplish this? Or is this something you would normaly write a oneline script for?

The script look like this

$recursiveChildItems = Get-ChildItem -Recurse
foreach ( $childItem in $recursiveChildItems )
{
$owner = Get-Acl $childItem.FullName | Select-Object Owner
$acl = Get-Acl $childItem.FullName | Select-Object AccessToString

Write-Host "File:" `t $childItem.FullName
Write-Host "Owner:" `t $owner.Owner
Write-Host "ACL:" `t `t $acl.AccessToString
Write-Host `n
}

Regards
Erik

halr9000User is Offline
Basic Member
Basic Member
Posts:316

--
01 Sep 2008 10:21 PM  
There's a million ways to do it. Here is one:
Get-ChildItem -recurse | ForEach-Object {
    $acl = $_ | Get-Acl
    $_ | Add-Member -name Owner -value $acl.Owner -memberType noteproperty
    $_ | Add-Member -name ACL -value $acl.AccessToString -memberType noteproperty
    $_ | Select-Object Fullname, Owner, ACL
} | Format-List


Output:
FullName : C:\Documents and Settings\hrottenberg\My Documents\WindowsPowerShell\scrip <br>            ts\book\ch5\new-vm.PS1 <br> Owner    : ADMIN\hrottenberg <br> ACL      : BUILTIN\Administrators Allow  FullControl <br>            NT AUTHORITY\SYSTEM Allow  FullControl <br>            ADMIN\hrottenberg Allow  FullControl <br>            BUILTIN\Users Allow  ReadAndExecute, Synchronize <br>  <br> FullName : C:\Documents and Settings\hrottenberg\My Documents\WindowsPowerShell\scrip <br>            ts\book\ch5\Set-VMStartOrder.PS1 <br> Owner    : ADMIN\hrottenberg <br> ACL      : BUILTIN\Administrators Allow  FullControl <br>            NT AUTHORITY\SYSTEM Allow  FullControl <br>            ADMIN\hrottenberg Allow  FullControl <br>            BUILTIN\Users Allow  ReadAndExecute, Synchronize
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer