mirror of
https://github.com/EvotecIT/GPOZaurr.git
synced 2026-07-26 11:49:17 +00:00
Update
This commit is contained in:
@@ -76,7 +76,8 @@
|
|||||||
|
|
||||||
[Parameter(ParameterSetName = 'Type')]
|
[Parameter(ParameterSetName = 'Type')]
|
||||||
[Parameter(ParameterSetName = 'Named')]
|
[Parameter(ParameterSetName = 'Named')]
|
||||||
[int] $LimitProcessing = [int32]::MaxValue
|
[int] $LimitProcessing = [int32]::MaxValue,
|
||||||
|
[switch] $Force
|
||||||
)
|
)
|
||||||
Begin {
|
Begin {
|
||||||
#Write-Verbose "Set-GPOZaurrOwner - Getting ADAdministrativeGroups"
|
#Write-Verbose "Set-GPOZaurrOwner - Getting ADAdministrativeGroups"
|
||||||
@@ -114,45 +115,50 @@
|
|||||||
$AdministrativeGroupSysvol = $null
|
$AdministrativeGroupSysvol = $null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($Type -eq 'NotAdministrative') {
|
if ($Force) {
|
||||||
if (-not $AdministrativeGroup -or (-not $AdministrativeGroupSysvol -and -not $SkipSysvol)) {
|
Write-Verbose "Set-GPOZaurrOwner - Force was used to push new owner to $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner)."
|
||||||
$_
|
$_
|
||||||
} else {
|
|
||||||
if ($AdministrativeGroup -ne $AdministrativeGroupSysvol) {
|
|
||||||
Write-Verbose "Set-GPOZaurrOwner - Detected mismatch GPO: $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner). Fixing required."
|
|
||||||
$_
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} elseif ($Type -eq 'Unknown') {
|
|
||||||
if (-not $_.Owner -or (-not $_.SysvolOwner -and -not $SkipSysvol)) {
|
|
||||||
$_
|
|
||||||
}
|
|
||||||
} elseif ($Type -eq 'NotMatching') {
|
|
||||||
if ($SkipSysvol) {
|
|
||||||
Write-Verbose "Set-GPOZaurrOwner - Detected mismatch GPO: $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner). SysVol scanning is disabled. Skipping."
|
|
||||||
} else {
|
|
||||||
if ($AdministrativeGroup -ne $AdministrativeGroupSysvol) {
|
|
||||||
#Write-Verbose "Set-GPOZaurrOwner - Detected mismatch GPO: $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner). Fixing required."
|
|
||||||
$_
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
# we run with no type, that means we need to either set it to principal or to Administrative
|
if ($Type -eq 'NotAdministrative') {
|
||||||
if ($_.Owner) {
|
if (-not $AdministrativeGroup -or (-not $AdministrativeGroupSysvol -and -not $SkipSysvol)) {
|
||||||
# we check if Principal is not set
|
$_
|
||||||
$AdministrativeGroup = $ADAdministrativeGroups['ByNetBIOS']["$($_.Owner)"]
|
} else {
|
||||||
if (-not $SkipSysvol -and $_.SysvolOwner) {
|
if ($AdministrativeGroup -ne $AdministrativeGroupSysvol) {
|
||||||
$AdministrativeGroupSysvol = $ADAdministrativeGroups['ByNetBIOS']["$($_.SysvolOwner)"]
|
Write-Verbose "Set-GPOZaurrOwner - Detected mismatch GPO: $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner). Fixing required."
|
||||||
if (-not $AdministrativeGroup -or -not $AdministrativeGroupSysvol) {
|
|
||||||
$_
|
$_
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} elseif ($Type -eq 'Unknown') {
|
||||||
|
if (-not $_.Owner -or (-not $_.SysvolOwner -and -not $SkipSysvol)) {
|
||||||
|
$_
|
||||||
|
}
|
||||||
|
} elseif ($Type -eq 'NotMatching') {
|
||||||
|
if ($SkipSysvol) {
|
||||||
|
Write-Verbose "Set-GPOZaurrOwner - Detected mismatch GPO: $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner). SysVol scanning is disabled. Skipping."
|
||||||
|
} else {
|
||||||
|
if ($AdministrativeGroup -ne $AdministrativeGroupSysvol) {
|
||||||
|
#Write-Verbose "Set-GPOZaurrOwner - Detected mismatch GPO: $($_.DisplayName) from domain: $($_.DomainName) - owner $($_.Owner) / sysvol owner $($_.SysvolOwner). Fixing required."
|
||||||
|
$_
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
# we run with no type, that means we need to either set it to principal or to Administrative
|
||||||
|
if ($_.Owner) {
|
||||||
|
# we check if Principal is not set
|
||||||
|
$AdministrativeGroup = $ADAdministrativeGroups['ByNetBIOS']["$($_.Owner)"]
|
||||||
|
if (-not $SkipSysvol -and $_.SysvolOwner) {
|
||||||
|
$AdministrativeGroupSysvol = $ADAdministrativeGroups['ByNetBIOS']["$($_.SysvolOwner)"]
|
||||||
|
if (-not $AdministrativeGroup -or -not $AdministrativeGroupSysvol) {
|
||||||
|
$_
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (-not $AdministrativeGroup) {
|
||||||
|
$_
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (-not $AdministrativeGroup) {
|
$_
|
||||||
$_
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
$_
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} | Select-Object -First $LimitProcessing | ForEach-Object -Process {
|
} | Select-Object -First $LimitProcessing | ForEach-Object -Process {
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
Describe 'GPO Owners Management - Simple' {
|
||||||
|
BeforeAll {
|
||||||
|
# just in case some tests failed before and added user stays
|
||||||
|
Import-Module $PSScriptRoot\..\*.psd1 -Force
|
||||||
|
|
||||||
|
}
|
||||||
|
It 'Get-GPOZaurrOwner - Should return proper data' {
|
||||||
|
$GPOs = Get-GPOZaurrOwner -IncludeSysvol
|
||||||
|
$GPOs.Count | Should -BeGreaterThan 5
|
||||||
|
$GPOs[0].PSObject.Properties.Name | Should -Be @(
|
||||||
|
'DisplayName', 'DomainName',
|
||||||
|
'GUID', 'Owner', 'OwnerSID',
|
||||||
|
'OwnerType', 'SysvolOwner', 'SysvolSid',
|
||||||
|
'SysvolType', 'SysvolPath', 'IsOwnerConsistent',
|
||||||
|
'IsOwnerAdministrative', 'SysvolExists', 'DistinguishedName'
|
||||||
|
)
|
||||||
|
}
|
||||||
|
It 'Set-GPOZaurrOwner - Should set proper data' {
|
||||||
|
Set-GPOZaurrOwner -GPOName 'TEST | GPOZaurr Permissions Testing' -Verbose -Principal 'przemyslaw.klys' -WhatIf:$false -Force
|
||||||
|
}
|
||||||
|
It 'Get-GPOZaurrOwner - Should return proper data for one GPO' {
|
||||||
|
$GPOs = Get-GPOZaurrOwner -IncludeSysvol -GPOName 'TEST | GPOZaurr Permissions Testing'
|
||||||
|
$GPOs.SysvolOwner | Should -Be 'EVOTEC\przemyslaw.klys'
|
||||||
|
$GPOs.SysvolType | Should -Be 'NotAdministrative'
|
||||||
|
$GPOs.Owner | Should -Be 'EVOTEC\przemyslaw.klys'
|
||||||
|
$GPOs.OwnerType | Should -Be 'NotAdministrative'
|
||||||
|
$GPOS.IsOwnerConsistent | Should -Be $true
|
||||||
|
$GPOS.IsOwnerAdministrative | Should -Be $false
|
||||||
|
}
|
||||||
|
It 'Set-GPOZaurrOwner - Should set proper data' {
|
||||||
|
Set-GPOZaurrOwner -GPOName 'TEST | GPOZaurr Permissions Testing' -Verbose
|
||||||
|
}
|
||||||
|
It 'Get-GPOZaurrOwner - Should return proper data for one GPO (Domain Admins)' {
|
||||||
|
$GPOs = Get-GPOZaurrOwner -IncludeSysvol -GPOName 'TEST | GPOZaurr Permissions Testing'
|
||||||
|
$GPOs.SysvolOwner | Should -Be 'EVOTEC\Domain Admins'
|
||||||
|
$GPOs.SysvolType | Should -Be 'Administrative'
|
||||||
|
$GPOs.Owner | Should -Be 'EVOTEC\Domain Admins'
|
||||||
|
$GPOs.OwnerType | Should -Be 'Administrative'
|
||||||
|
$GPOS.IsOwnerConsistent | Should -Be $true
|
||||||
|
$GPOS.IsOwnerAdministrative | Should -Be $true
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user