This commit is contained in:
Przemyslaw Klys
2020-12-06 14:41:07 +01:00
parent 238aac6972
commit c5779cdae0
3 changed files with 49 additions and 51 deletions
+28 -4
View File
@@ -8,7 +8,8 @@
[System.Collections.IDictionary] $ADAdministrativeGroups, [System.Collections.IDictionary] $ADAdministrativeGroups,
[string] $Splitter = [System.Environment]::NewLine, [string] $Splitter = [System.Environment]::NewLine,
[switch] $ReturnObject, [switch] $ReturnObject,
[System.Collections.IDictionary] $ExcludeGroupPolicies [System.Collections.IDictionary] $ExcludeGroupPolicies,
[string[]] $Type
) )
if ($XMLContent.GPO.LinksTo) { if ($XMLContent.GPO.LinksTo) {
$LinkSplit = ([Array] $XMLContent.GPO.LinksTo).Where( { $_.Enabled -eq $true }, 'Split') $LinkSplit = ([Array] $XMLContent.GPO.LinksTo).Where( { $_.Enabled -eq $true }, 'Split')
@@ -170,7 +171,7 @@
} }
} }
if ($PermissionsOnly) { if ($PermissionsOnly) {
[PsCustomObject] @{ $GPOOutput = [PsCustomObject] @{
'DisplayName' = $XMLContent.GPO.Name 'DisplayName' = $XMLContent.GPO.Name
'DomainName' = $XMLContent.GPO.Identifier.Domain.'#text' 'DomainName' = $XMLContent.GPO.Identifier.Domain.'#text'
'GUID' = $XMLContent.GPO.Identifier.Identifier.InnerText -replace '{' -replace '}' 'GUID' = $XMLContent.GPO.Identifier.Identifier.InnerText -replace '{' -replace '}'
@@ -201,7 +202,7 @@
} }
} }
} elseif ($OwnerOnly) { } elseif ($OwnerOnly) {
[PsCustomObject] @{ $GPOOutput = [PsCustomObject] @{
'DisplayName' = $XMLContent.GPO.Name 'DisplayName' = $XMLContent.GPO.Name
'DomainName' = $XMLContent.GPO.Identifier.Domain.'#text' 'DomainName' = $XMLContent.GPO.Identifier.Domain.'#text'
'GUID' = $XMLContent.GPO.Identifier.Identifier.InnerText -replace '{' -replace '}' 'GUID' = $XMLContent.GPO.Identifier.Identifier.InnerText -replace '{' -replace '}'
@@ -212,7 +213,7 @@
'GPODistinguishedName' = $GPO.Path 'GPODistinguishedName' = $GPO.Path
} }
} else { } else {
[PsCustomObject] @{ $GPOOutput = [PsCustomObject] @{
'DisplayName' = $XMLContent.GPO.Name 'DisplayName' = $XMLContent.GPO.Name
'DomainName' = $XMLContent.GPO.Identifier.Domain.'#text' 'DomainName' = $XMLContent.GPO.Identifier.Domain.'#text'
'GUID' = $XMLContent.GPO.Identifier.Identifier.InnerText -replace '{' -replace '}' 'GUID' = $XMLContent.GPO.Identifier.Identifier.InnerText -replace '{' -replace '}'
@@ -297,4 +298,27 @@
'GPOObject' = $GPO 'GPOObject' = $GPO
} }
} }
if ($PermissionsOnly -or $OwnerOnly) {
$GPOOutput
} else {
if (-not $Type -or $Type -contains 'All') {
$GPOOutput
} else {
if ($Type -contains 'Empty') {
if ($GPOOutput.Empty -eq $true) {
$GPOOutput
}
}
if ($Type -contains 'Unlinked') {
if ($GPOOutput.Linked -eq $false) {
$GPOOutput
}
}
if ($Type -contains 'Disabled') {
if ($GPOOutput.Enabled -eq $false) {
$GPOOutput
}
}
}
}
} }
+12 -43
View File
@@ -44,7 +44,7 @@
[cmdletBinding(SupportsShouldProcess)] [cmdletBinding(SupportsShouldProcess)]
param( param(
[int] $LimitProcessing, [int] $LimitProcessing,
[validateset('All', 'Empty', 'Unlinked')][string[]] $Type = 'All', [validateset('Empty', 'Unlinked', 'Disabled', 'All')][string[]] $Type = 'All',
[alias('ForestName')][string] $Forest, [alias('ForestName')][string] $Forest,
[string[]] $ExcludeDomains, [string[]] $ExcludeDomains,
[alias('Domain', 'Domains')][string[]] $IncludeDomains, [alias('Domain', 'Domains')][string[]] $IncludeDomains,
@@ -63,49 +63,18 @@
$Count = 0 $Count = 0
} }
Process { Process {
Get-GPOZaurr -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation | ForEach-Object { Get-GPOZaurr -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation -Type $Type | ForEach-Object {
if ($Type -contains 'All') { $GPO = $_
Write-Verbose "Backup-GPOZaurr - Backing up GPO $($_.DisplayName) from $($_.DomainName)" Write-Verbose "Backup-GPOZaurr - Backing up GPO $($GPO.DisplayName) from $($GPO.DomainName)"
$Count++ $Count++
try { try {
$BackupInfo = Backup-GPO -Guid $_.GUID -Domain $_.DomainName -Path $BackupFinalPath -ErrorAction Stop #-Server $QueryServer $BackupInfo = Backup-GPO -Guid $GPO.GUID -Domain $GPO.DomainName -Path $BackupFinalPath -ErrorAction Stop
$BackupInfo $BackupInfo
} catch { } catch {
Write-Warning "Backup-GPOZaurr - Backing up GPO $($_.DisplayName) from $($_.DomainName) failed: $($_.Exception.Message)" Write-Warning "Backup-GPOZaurr - Backing up GPO $($GPO.DisplayName) from $($GPO.DomainName) failed: $($_.Exception.Message)"
}
if ($LimitProcessing -eq $Count) {
break
}
} }
if ($Type -notcontains 'All' -and $Type -contains 'Empty') { if ($LimitProcessing -eq $Count) {
if ($_.ComputerSettingsAvailable -eq $false -and $_.UserSettingsAvailable -eq $false) { break
Write-Verbose "Backup-GPOZaurr - Backing up GPO $($_.DisplayName) from $($_.DomainName)"
$Count++
try {
$BackupInfo = Backup-GPO -Guid $_.GUID -Domain $_.DomainName -Path $BackupFinalPath -ErrorAction Stop #-Server $QueryServer
$BackupInfo
} catch {
Write-Warning "Backup-GPOZaurr - Backing up GPO $($_.DisplayName) from $($_.DomainName) failed: $($_.Exception.Message)"
}
if ($LimitProcessing -eq $Count) {
break
}
}
}
if ($Type -notcontains 'All' -and $Type -contains 'Unlinked') {
if ($_.Linked -eq $false) {
Write-Verbose "Backup-GPOZaurr - Backing up GPO $($_.DisplayName) from $($_.DomainName)"
$Count++
try {
$BackupInfo = Backup-GPO -Guid $_.GUID -Domain $_.DomainName -Path $BackupFinalPath -ErrorAction Stop #-Server $QueryServer
$BackupInfo
} catch {
Write-Warning "Backup-GPOZaurr - Backing up GPO $($_.DisplayName) from $($_.DomainName) failed: $($_.Exception.Message)"
}
if ($LimitProcessing -eq $Count) {
break
}
}
} }
} }
} }
+9 -4
View File
@@ -5,6 +5,8 @@
[string] $GPOName, [string] $GPOName,
[alias('GUID', 'GPOID')][string] $GPOGuid, [alias('GUID', 'GPOID')][string] $GPOGuid,
[validateset('Empty', 'Unlinked', 'Disabled', 'All')][string[]] $Type,
[alias('ForestName')][string] $Forest, [alias('ForestName')][string] $Forest,
[string[]] $ExcludeDomains, [string[]] $ExcludeDomains,
[alias('Domain', 'Domains')][string[]] $IncludeDomains, [alias('Domain', 'Domains')][string[]] $IncludeDomains,
@@ -42,6 +44,9 @@
} }
} }
} }
if ($OwnerOnly -or $PermissionsOnly -and $Type) {
Write-Warning "Get-GPOZaurr - Using PermissionOnly or OwnerOnly with Type is not supported. "
}
} }
Process { Process {
if (-not $GPOPath) { if (-not $GPOPath) {
@@ -61,7 +66,7 @@
Write-Warning "Get-GPOZaurr - Failed to get GPOReport: $($_.Exception.Message). Skipping." Write-Warning "Get-GPOZaurr - Failed to get GPOReport: $($_.Exception.Message). Skipping."
continue continue
} }
Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -GPO $_ -PermissionsOnly:$PermissionsOnly.IsPresent -ADAdministrativeGroups $ADAdministrativeGroups -ReturnObject:$ReturnObject.IsPresent -ExcludeGroupPolicies $ExcludeGPO Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -GPO $_ -PermissionsOnly:$PermissionsOnly.IsPresent -ADAdministrativeGroups $ADAdministrativeGroups -ReturnObject:$ReturnObject.IsPresent -ExcludeGroupPolicies $ExcludeGPO -Type $Type
} else { } else {
$_ $_
} }
@@ -79,7 +84,7 @@
Write-Warning "Get-GPOZaurr - Failed to get GPOReport: $($_.Exception.Message). Skipping." Write-Warning "Get-GPOZaurr - Failed to get GPOReport: $($_.Exception.Message). Skipping."
continue continue
} }
Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -GPO $_ -PermissionsOnly:$PermissionsOnly.IsPresent -ADAdministrativeGroups $ADAdministrativeGroups -ReturnObject:$ReturnObject.IsPresent -ExcludeGroupPolicies $ExcludeGPO Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -GPO $_ -PermissionsOnly:$PermissionsOnly.IsPresent -ADAdministrativeGroups $ADAdministrativeGroups -ReturnObject:$ReturnObject.IsPresent -ExcludeGroupPolicies $ExcludeGPO -Type $Type
} else { } else {
$_ $_
} }
@@ -97,7 +102,7 @@
Write-Warning "Get-GPOZaurr - Failed to get GPOReport: $($_.Exception.Message). Skipping." Write-Warning "Get-GPOZaurr - Failed to get GPOReport: $($_.Exception.Message). Skipping."
continue continue
} }
Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -GPO $_ -PermissionsOnly:$PermissionsOnly.IsPresent -ADAdministrativeGroups $ADAdministrativeGroups -ReturnObject:$ReturnObject.IsPresent -ExcludeGroupPolicies $ExcludeGPO Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -GPO $_ -PermissionsOnly:$PermissionsOnly.IsPresent -ADAdministrativeGroups $ADAdministrativeGroups -ReturnObject:$ReturnObject.IsPresent -ExcludeGroupPolicies $ExcludeGPO -Type $Type
} else { } else {
$_ $_
} }
@@ -110,7 +115,7 @@
Get-ChildItem -LiteralPath $Path -Recurse -Filter *.xml | ForEach-Object { Get-ChildItem -LiteralPath $Path -Recurse -Filter *.xml | ForEach-Object {
$XMLContent = [XML]::new() $XMLContent = [XML]::new()
$XMLContent.Load($_.FullName) $XMLContent.Load($_.FullName)
Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -PermissionsOnly:$PermissionsOnly.IsPresent -ExcludeGroupPolicies $ExcludeGPO Get-XMLGPO -OwnerOnly:$OwnerOnly.IsPresent -XMLContent $XMLContent -PermissionsOnly:$PermissionsOnly.IsPresent -ExcludeGroupPolicies $ExcludeGPO -Type $Type
} }
Write-Verbose "Get-GPOZaurr - Finished GPO content from XML files" Write-Verbose "Get-GPOZaurr - Finished GPO content from XML files"
} }