|
|
|
@@ -110,7 +110,15 @@
|
|
|
|
|
[parameter(ParameterSetName = 'ADObject')]
|
|
|
|
|
[parameter(ParameterSetName = 'Linked')]
|
|
|
|
|
[parameter(ParameterSetName = 'Level')]
|
|
|
|
|
[System.Collections.IDictionary] $ExtendedForestInformation
|
|
|
|
|
[System.Collections.IDictionary] $ExtendedForestInformation,
|
|
|
|
|
|
|
|
|
|
[Parameter(ParameterSetName = 'GPOGUID')]
|
|
|
|
|
[Parameter(ParameterSetName = 'GPOName')]
|
|
|
|
|
[parameter(ParameterSetName = 'Filter')]
|
|
|
|
|
[parameter(ParameterSetName = 'ADObject')]
|
|
|
|
|
[parameter(ParameterSetName = 'Linked')]
|
|
|
|
|
[parameter(ParameterSetName = 'Level')]
|
|
|
|
|
[switch] $LimitAdministrativeGroupsToDomain
|
|
|
|
|
)
|
|
|
|
|
if ($PermissionRules) {
|
|
|
|
|
$Rules = & $PermissionRules
|
|
|
|
@@ -119,8 +127,12 @@
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
$ForestInformation = Get-WinADForestDetails -Extended -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation
|
|
|
|
|
$ADAdministrativeGroups = Get-ADADministrativeGroups -Type DomainAdmins, EnterpriseAdmins -Forest $Forest #-IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ForestInformation
|
|
|
|
|
|
|
|
|
|
if ($LimitAdministrativeGroupsToDomain) {
|
|
|
|
|
# This will get administrative based on IncludeDomains if given. It means that if GPO has Domain admins added from multiple domains it will only find one, and remove all other Domain Admins (if working with Domain Admins that is)
|
|
|
|
|
$ADAdministrativeGroups = Get-ADADministrativeGroups -Type DomainAdmins, EnterpriseAdmins -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ForestInformation
|
|
|
|
|
} else {
|
|
|
|
|
$ADAdministrativeGroups = Get-ADADministrativeGroups -Type DomainAdmins, EnterpriseAdmins -Forest $Forest #-IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ForestInformation
|
|
|
|
|
}
|
|
|
|
|
if ($PSCmdlet.ParameterSetName -ne 'Level') {
|
|
|
|
|
$Splat = @{
|
|
|
|
|
Forest = $Forest
|
|
|
|
@@ -173,7 +185,7 @@
|
|
|
|
|
Set-GPOZaurrOwner -GPOGuid $GPO.Guid -IncludeDomains $GPO.Domain -Principal $Rule.Principal -WhatIf:$WhatIfPreference
|
|
|
|
|
}
|
|
|
|
|
} elseif ($Rule.Action -eq 'Remove') {
|
|
|
|
|
$GPOPermissions = Get-GPOZaurrPermission -GPOGuid $GPO.GUID -IncludeDomains $GPO.DomainName -IncludePermissionType $Rule.IncludePermissionType -ExcludePermissionType $Rule.ExcludePermissionType -Type $Rule.Type -IncludeGPOObject -PermitType $Rule.PermitType -Principal $Rule.Principal -PrincipalType $Rule.PrincipalType -ExcludePrincipal $Rule.ExcludePrincipal -ExcludePrincipalType $Rule.ExcludePrincipalType
|
|
|
|
|
$GPOPermissions = Get-GPOZaurrPermission -GPOGuid $GPO.GUID -IncludeDomains $GPO.DomainName -IncludePermissionType $Rule.IncludePermissionType -ExcludePermissionType $Rule.ExcludePermissionType -Type $Rule.Type -IncludeGPOObject -PermitType $Rule.PermitType -Principal $Rule.Principal -PrincipalType $Rule.PrincipalType -ExcludePrincipal $Rule.ExcludePrincipal -ExcludePrincipalType $Rule.ExcludePrincipalType -ADAdministrativeGroups $ADAdministrativeGroups
|
|
|
|
|
foreach ($Permission in $GPOPermissions) {
|
|
|
|
|
Remove-PrivPermission -Principal $Permission.Sid -PrincipalType Sid -GPOPermission $Permission -IncludePermissionType $Permission.Permission
|
|
|
|
|
}
|
|
|
|
@@ -226,7 +238,7 @@
|
|
|
|
|
Set-GPOZaurrOwner -GPOGuid $GPO.Guid -IncludeDomains $GPO.Domain -Principal $Rule.Principal -WhatIf:$WhatIfPreference
|
|
|
|
|
}
|
|
|
|
|
} elseif ($Rule.Action -eq 'Remove') {
|
|
|
|
|
$GPOPermissions = Get-GPOZaurrPermission -GPOGuid $GPO.GUID -IncludeDomains $GPO.DomainName -IncludePermissionType $Rule.IncludePermissionType -ExcludePermissionType $Rule.ExcludePermissionType -Type $Rule.Type -IncludeGPOObject -PermitType $Rule.PermitType -Principal $Rule.Principal -PrincipalType $Rule.PrincipalType -ExcludePrincipal $Rule.ExcludePrincipal -ExcludePrincipalType $Rule.ExcludePrincipalType
|
|
|
|
|
$GPOPermissions = Get-GPOZaurrPermission -GPOGuid $GPO.GUID -IncludeDomains $GPO.DomainName -IncludePermissionType $Rule.IncludePermissionType -ExcludePermissionType $Rule.ExcludePermissionType -Type $Rule.Type -IncludeGPOObject -PermitType $Rule.PermitType -Principal $Rule.Principal -PrincipalType $Rule.PrincipalType -ExcludePrincipal $Rule.ExcludePrincipal -ExcludePrincipalType $Rule.ExcludePrincipalType -ADAdministrativeGroups $ADAdministrativeGroups
|
|
|
|
|
foreach ($Permission in $GPOPermissions) {
|
|
|
|
|
Remove-PrivPermission -Principal $Permission.Sid -PrincipalType Sid -GPOPermission $Permission -IncludePermissionType $Permission.Permission
|
|
|
|
|
}
|
|
|
|
|