Get-Acl without inheritance<p>Hello,</p> <p>When i type the following line in PS &quot;Get-ChildItem I:\ -recurse -exclude *.* | Get-Acl&quot; It lists all the directories and their security rights. I need to be able to only list the folders which have the security set on them and not inherited by parent folder.</p> <p>Is this possible?</p> <p> </p> <p>What I'm aiming for is a script to list all parent-rights in our file-structure. Perhaps this is possible to do some other way?</p> <p> </p> <p>Best Regards,</p> <p>Joans Bson</p>© 2009 Microsoft Corporation. All rights reserved.Fri, 16 Oct 2009 10:07:55 Z6d45592a-bbb8-4a4c-bb3d-7e562b80994fhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#6d45592a-bbb8-4a4c-bb3d-7e562b80994fhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#6d45592a-bbb8-4a4c-bb3d-7e562b80994fJonas_Bsonhttp://social.technet.microsoft.com/Profile/en-US/?user=Jonas_BsonGet-Acl without inheritance<p>Hello,</p> <p>When i type the following line in PS &quot;Get-ChildItem I:\ -recurse -exclude *.* | Get-Acl&quot; It lists all the directories and their security rights. I need to be able to only list the folders which have the security set on them and not inherited by parent folder.</p> <p>Is this possible?</p> <p> </p> <p>What I'm aiming for is a script to list all parent-rights in our file-structure. Perhaps this is possible to do some other way?</p> <p> </p> <p>Best Regards,</p> <p>Joans Bson</p>Fri, 23 Jan 2009 16:34:20 Z2009-01-23T16:34:20Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#d2f4a725-c5ba-415a-ba83-199938ad838dhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#d2f4a725-c5ba-415a-ba83-199938ad838dMarco Shawhttp://social.technet.microsoft.com/Profile/en-US/?user=Marco%20ShawGet-Acl without inheritanceI think you can get this by looking at the SDDL value for a folder.  There may be easier ways, but I think this will work for you:<div style="overflow:auto;background-color:white;line-height:100% ! important;font-family:Courier New;font-size:11px"><table style="border-width:0px;margin:2px 0px;width:99%;border-collapse:collapse;background-color:rgb(255, 255, 255)" cellpadding=0 cellspacing=0><col style="border-right:1px solid gray;font-family:Courier New;font-size:11px;background-color:rgb(238, 238, 238);padding-right:5px;padding-left:10px;width:5px;color:gray;text-align:right;vertical-align:top"><col style="font-family:Courier New;font-size:11px;padding-left:10px;white-space:nowrap"><tbody><tr><td><nobr>1</nobr></td><td><font style="font-size:11px">$no_inh=</font><font style="color:blue">get</font><font style="font-size:11px">-acl .|foreach{$_.sddl} </font></td></tr><tr><td><nobr>2</nobr></td><td style="background-color:rgb(247, 247, 247)">gci . -rec|where{$_.psiscontainer}|<font style="color:blue">foreach</font><font style="font-size:11px">{</font><font style="color:blue">if</font><font style="font-size:11px">(($_|</font><font style="color:blue">get</font><font style="font-size:11px">-acl|</font><font style="color:blue">foreach</font><font style="font-size:11px">{$_.sddl}) -eq $no_inh){$_.fullname}} </font></td></tr></tbody></table></div><p>On line 1, I move to a directory where I know inheritance has been removed.  I save the SDDL string to a variable.</p><p>On line 2, I get the ACLs and SDDL for every directory, then compare the SDDL against my variable, if the SDDLs match, I have a directory without inheritance, and I print out the full directory name.</p><p><i>[EDIT: I reread your post.  I think I've missed the point.  Please provide feedback.]</i><br></p>Fri, 23 Jan 2009 19:20:54 Z2009-01-24T01:39:53Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#6dc8dd7b-eb06-45fc-8db7-16f881a5a1behttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#6dc8dd7b-eb06-45fc-8db7-16f881a5a1bedmdamenhttp://social.technet.microsoft.com/Profile/en-US/?user=dmdamenGet-Acl without inheritance The line of code below will show you all file names that have explicit security set.<br><br>get-childitem -recurse | where-object {$_.mode -match &quot;d&quot;} | %{$file=$_;get-acl $($_.FullName)} | %{$_.GetAccessRules($True,$False,[Security.Principal.SecurityIdentifier]) | %{write-host &quot;$($file.FullName) has explicit security set&quot;}}<br>Sun, 01 Feb 2009 18:38:25 Z2009-02-01T18:38:53Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#a2101d5a-ff2d-4066-8100-22216807968chttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#a2101d5a-ff2d-4066-8100-22216807968cScott Meilickehttp://social.technet.microsoft.com/Profile/en-US/?user=Scott%20MeilickeGet-Acl without inheritanceI know this thread is quite old, but here is how I did this. Keep in mind I am quite new to powershell, so I like to spell things out. I would be interested in techniques to speed this up. if ($args.length -ne 2) { &quot;This script takes exactly two arguments, in this order: file for output, a path to analyze&quot; } else { $path = $args[1] $outPutFile = $args[0] $startDate = Get-Date #Build information for the header of the output file. `r`n is a carrage return/line feed. $header = &quot;Start: &quot; + $startDate + &quot;`r`n&quot; + &quot;Output file: &quot; + $outPutFile + &quot;`r`n&quot; + &quot;Path analyzed: &quot; + $path + &quot;`r`n&quot; out-file -encoding ASCII -filePath $outPutFile -append -InputObject $header # Get all directories, not files, get their ACLs, and stuff them into a variable ($dirs). $dirs = Get-ChildItem $path -Recurse -Force | ? { $_.GetType() -like 'System.IO.DirectoryInfo'} | get-ACL Foreach ($dir in $dirs) { Foreach ($Access in $dir.Access) { $Inherited = [string]$Access.IsInherited if ($Inherited -eq &quot;False&quot;) { $pathPieces = $dir.Path.split(&quot;:&quot;) $output = $PathPieces[2] + &quot;:&quot; + $pathPieces[3] + &quot;, &quot; + $Access.IdentityReference + &quot;, &quot; + $Access.FileSystemRights out-file -encoding ASCII -filePath $outPutFile -append -InputObject $output } } } $endDate = Get-Date $elapsedTime = $endDate - $startDate $footer = &quot;`r`nRun completed at: &quot; + $endDate + &quot;`r`n&quot; + &quot;Elapsed Time:`r`n&quot; + $elapsedTime + &quot;`r`n&quot; out-file -encoding ASCII -filePath $outPutFile -append -InputObject $footer } -Scott <div><br/></div> <div>EDIT - shoot, sorry for the crappy word wrapping.</div>Fri, 19 Jun 2009 18:14:16 Z2009-06-19T18:15:33Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#60e0528d-2d31-4ce6-a267-f60ebb070f12http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#60e0528d-2d31-4ce6-a267-f60ebb070f12cbreakerhttp://social.technet.microsoft.com/Profile/en-US/?user=cbreakerGet-Acl without inheritanceHi Scott, <br /> <br /> I can't seem to get your example to work.&nbsp;&nbsp;&nbsp; I'm really no powershell programmer and I think I have the wrapping all wrong.&nbsp; Since powershell uses CRLF's to seperate commands (against say Bash) when it's all on one big line it won't run.<br /> <br /> Any help?<br />Thu, 15 Oct 2009 14:34:11 Z2009-10-15T14:34:11Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#9c4c32a3-e1ed-4159-94cd-5c51efc23665http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#9c4c32a3-e1ed-4159-94cd-5c51efc23665cbreakerhttp://social.technet.microsoft.com/Profile/en-US/?user=cbreakerGet-Acl without inheritanceReplying to myself to enable e-mail notification..Thu, 15 Oct 2009 14:35:17 Z2009-10-15T14:35:17Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#1dfdcf92-c020-4866-96c9-51dbb25b3b22http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#1dfdcf92-c020-4866-96c9-51dbb25b3b22Marco Shawhttp://social.technet.microsoft.com/Profile/en-US/?user=Marco%20ShawGet-Acl without inheritanceI'll fix up the code in the next 24 hours and post it as a script, and that should help...<br />Thu, 15 Oct 2009 14:51:15 Z2009-10-15T14:51:15Zhttp://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#29a7b0ed-a6d6-48c2-a1fc-20cf522ba903http://social.technet.microsoft.com/Forums/en-US/winserverpowershell/thread/6d45592a-bbb8-4a4c-bb3d-7e562b80994f#29a7b0ed-a6d6-48c2-a1fc-20cf522ba903Marco Shawhttp://social.technet.microsoft.com/Profile/en-US/?user=Marco%20ShawGet-Acl without inheritanceI think this is fixed up properly.&nbsp; I haven't tested it yet:<br /> <br /> <pre lang="x-c#">if ($args.length -ne 2) { &quot;This script takes exactly two arguments, in this order: file for output, a path to analyze&quot; } else { $path = $args[1] $outPutFile = $args[0] $startDate = Get-Date #Build information for the header of the output file. `r`n is a carrage return/line feed. $header = &quot;Start: &quot; + $startDate + &quot;`r`n&quot; + &quot;Output file: &quot; + $outPutFile + &quot;`r`n&quot; + &quot;Path analyzed: &quot; + $path + &quot;`r`n&quot; out-file -encoding ASCII -filePath $outPutFile -append -InputObject $header # Get all directories, not files, get their ACLs, and stuff them into a variable ($dirs). $dirs = Get-ChildItem $path -Recurse -Force | ? { $_.GetType() -like 'System.IO.DirectoryInfo'} | get-ACL Foreach ($dir in $dirs) { Foreach ($Access in $dir.Access) { $Inherited = [string]$Access.IsInherited if ($Inherited -eq &quot;False&quot;) { $pathPieces = $dir.Path.split(&quot;:&quot;) $output = $PathPieces[2] + &quot;:&quot; + $pathPieces[3] + &quot;, &quot; + $Access.IdentityReference + &quot;, &quot; + $Access.FileSystemRights out-file -encoding ASCII -filePath $outPutFile -append -InputObject $output } } } $endDate = Get-Date $elapsedTime = $endDate - $startDate $footer = &quot;`r`nRun completed at: &quot; + $endDate + &quot;`r`n&quot; + &quot;Elapsed Time:`r`n&quot; + $elapsedTime + &quot;`r`n&quot; out-file -encoding ASCII -filePath $outPutFile -append -InputObject $footer }</pre>Fri, 16 Oct 2009 10:07:55 Z2009-10-16T10:07:55Z