header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Simple ACL script
Last Post 01 Sep 2008 02: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
Avatar

--
01 Sep 2008 01: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
    PowerShell MVP, Site Admin
    Advanced Member
    Advanced Member
    Posts:565
    Avatar

    --
    01 Sep 2008 02: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
    ts\book\ch5\new-vm.PS1
    Owner : ADMIN\hrottenberg
    ACL : BUILTIN\Administrators Allow FullControl
    NT AUTHORITY\SYSTEM Allow FullControl
    ADMIN\hrottenberg Allow FullControl
    BUILTIN\Users Allow ReadAndExecute, Synchronize

    FullName : C:\Documents and Settings\hrottenberg\My Documents\WindowsPowerShell\scrip
    ts\book\ch5\Set-VMStartOrder.PS1
    Owner : ADMIN\hrottenberg
    ACL : BUILTIN\Administrators Allow FullControl
    NT AUTHORITY\SYSTEM Allow FullControl
    ADMIN\hrottenberg Allow FullControl
    BUILTIN\Users Allow ReadAndExecute, Synchronize
    Community Director, PowerShellCommunity.org
    Co-host, PowerScripting Podcast
    Author, TechProsaic
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer