Welcome › Forums › General PowerShell Q&A › Get User ACL inheritance settings (SDHolder)
- This topic has 3 replies, 2 voices, and was last updated 3 weeks, 6 days ago by
Participant.
-
AuthorPosts
-
-
December 21, 2020 at 8:55 am #281570
Hello,
I need to find users in specific ou’s and of that users find out if they are protected accounts, where the SDholder groups are present , the “enable inheritance” setting (under security-advanced,enable inheritance ) and if not it needs to be restored to their ACL-Default .
I create a $ for tghe users with the admincount set to 1.
When I try to find out if the NTSecurity settings are Disabled powershell ask me to the property.
I have no clue what kind of property is missing at this point…Hopefully the answer can help me understand this :
PowerShell1234567891011121314151617181920212223242526272829$Ou1 = path....$Ou2 = path....$Ou3 = path....# The different OU's are put together in 1 Variabele$AdminOus = @()$AdminOus += $OUpathP01$AdminOus += $OUpathP02$AdminOus += $OUpathP03# 1. Get the users that are in the ou's and place them in a Variable called $Users$Users = @()$Users += Get-ADUser -Filter * -SearchBase $OUpathP01$Users += Get-ADUser -Filter * -SearchBase $OUpathP02$Users += Get-ADUser -Filter * -SearchBase $OUpathP03#Find Adminaccounts with admincount property = 1, and no SDHolder groups in ACLForeach($user in $Users){get-aduser $user -properties * |Where -Property admincount -EQ 1 |select -Property samaccountname, admincount |export-csv $exportpath -Append}#Find protected accounts in searchscope with inheritance disabled$Admincount = import-csv $exportpath.saForeach ($sam in $Admincount.samaccountname){Get-aduser -searchbase $Sam -filter * -properties ntsecuritydescriptor | where{($_.ntsecuritydescriptor.areaccessrulesprotected -eq $true) } |export-csv "D:\inheritance.csv"}Powershell returns a “error”:
PowerShell123456get-aduser -searchbase $Sam -filter * -properties ntsecuritydescriptor | where{($_.ntsecuritydescriptor.areaccessrulesprotected -eq $true) } |export-csv "D:\Users\adpiebak1d\Documents\PS-script\Output\inheritance.csv"}cmdlet Where-Object at command pipeline position 2Supply values for the following parameters:Property:thanx in advance
-
December 21, 2020 at 9:23 am #281576
Recommend a different approach. You’re getting the users 3 times from the same place with different properties. Here is something to try:
PowerShell123456789101112$adminOus = 'OU=Path1,DC=mydomain,DC=com','OU=Path1,DC=mydomain,DC=com','OU=Path1,DC=mydomain,DC=com'$users = foreach ($ou in $adminOus) {Get-ADUser -Filter * -SearchBase $ou -Property admincount,ntsecuritydescriptor |Select-Object -Property *,@{Name='AreaAccessRulesProtected';Expression={$_.ntsecuritydescriptor.areaccessrulesprotected}}}$users | Where-Object -FilterScript {$_.AdminCount -eq 1 -and $_.AreaAccessRulesProtected -eq $true}Don’t have AD handy to test the parse of ntsecuritydesciptor, but even if the calculated expression doesn’t get you a boolean true\false, you still have it for the user and can attempt to re-parse it.
Edit: Actually looking at it, most likely the issue you is the query for the ntsecuritydescriptor is returning null and you are piping it to Export, but it’s NULL, hence no properties to export.
-
This reply was modified 4 weeks ago by
Rob Simmers.
-
This reply was modified 4 weeks ago by
-
December 22, 2020 at 3:09 am #281743
Recommend a different approach. You’re getting the users 3 times from the same place with different properties. Here is something to try:
<link rel=”stylesheet” type=”text/css” href=”https://powershell.org/wp-content/plugins/urvanov-syntax-highlighter/themes/powershell-ise/powershell-ise.css”>
<link rel=”stylesheet” type=”text/css” href=”https://powershell.org/wp-content/plugins/urvanov-syntax-highlighter/fonts/liberation-mono.css”>PowerShell
<textarea class=”urvanov-syntax-highlighter-plain print-no” data-settings=”dblclick” readonly=”” style=”tab-size: 4; font-size: 14px !important; line-height: 18px !important; z-index: 0; opacity: 0;”>$adminOus = ‘OU=Path1,DC=mydomain,DC=com’,
‘OU=Path1,DC=mydomain,DC=com’,
‘OU=Path1,DC=mydomain,DC=com’$users = foreach ($ou in $adminOus) {
Get-ADUser -Filter * -SearchBase $ou -Property admincount,ntsecuritydescriptor |
Select-Object -Property *,
@{Name=’AreaAccessRulesProtected’;Expression={$_.ntsecuritydescriptor.areaccessrulesprotected}}
}$users | Where-Object -FilterScript {$_.AdminCount -eq 1 -and $_.AreaAccessRulesProtected -eq $true}</textarea>
123456789101112$adminOus = ‘OU=Path1,DC=mydomain,DC=com’,‘OU=Path1,DC=mydomain,DC=com’,‘OU=Path1,DC=mydomain,DC=com’$users = foreach ($ou in $adminOus) {Get-ADUser -Filter * -SearchBase $ou -Property admincount,ntsecuritydescriptor |Select-Object -Property *,@{Name=‘AreaAccessRulesProtected’;Expression={$_.ntsecuritydescriptor.areaccessrulesprotected}}}$users | Where-Object -FilterScript {$_.AdminCount -eq 1 -and $_.AreaAccessRulesProtected -eq $true}Don’t have AD handy to test the parse of ntsecuritydesciptor, but even if the calculated expression doesn’t get you a boolean true\false, you still have it for the user and can attempt to re-parse it.
Edit: Actually looking at it, most likely the issue you is the query for the ntsecuritydescriptor is returning null and you are piping it to Export, but it’s NULL, hence no properties to export.
@Rob Simmers,
Thanks a lot..
It worked really well.Maybe you also have a good idea, how I get just the SDholder groups as a output..?
I use :PowerShell1ACL =(Get-ACL "AD:$((Get-ADUser adpiebak1d).distinguishedname)").accessto find the ACL groups, however I struggle by getting just the 4 SDholder groups.
grtz
Pieter
-
December 22, 2020 at 9:03 am #281813
It should be a simple where clause. This example is filtering out identities like ‘admin’:
PowerShell12345678910111213141516171819202122232425262728293031323334353637383940414243444546PS C:\Users\rasim> c:\Users\rasim\Desktop\temp.ps1FileSystemRights : FullControlAccessControlType : AllowIdentityReference : BUILTIN\AdministratorsIsInherited : TrueInheritanceFlags : NonePS C:\Users\rasim> (Get-ACL -Path C:\Scripts\file1.txt).AccessFileSystemRights : FullControlAccessControlType : AllowIdentityReference : BUILTIN\AdministratorsIsInherited : TrueInheritanceFlags : NonePropagationFlags : NoneFileSystemRights : FullControlAccessControlType : AllowIdentityReference : NT AUTHORITY\SYSTEMIsInherited : TrueInheritanceFlags : NonePropagationFlags : NoneFileSystemRights : ReadAndExecute, SynchronizeAccessControlType : AllowIdentityReference : BUILTIN\UsersIsInherited : TrueInheritanceFlags : NonePropagationFlags : NoneFileSystemRights : Modify, SynchronizeAccessControlType : AllowIdentityReference : NT AUTHORITY\Authenticated UsersIsInherited : TrueInheritanceFlags : NonePropagationFlags : NonePS C:\Users\rasim> (Get-ACL -Path C:\Scripts\file1.txt).Access | Where{$_.IdentityReference -like '*admin*'}FileSystemRights : FullControlAccessControlType : AllowIdentityReference : BUILTIN\AdministratorsIsInherited : TrueInheritanceFlags : NonePropagationFlags : None-
This reply was modified 3 weeks, 6 days ago by
Rob Simmers.
-
This reply was modified 3 weeks, 6 days ago by
-
-
AuthorPosts
- You must be logged in to reply to this topic.