From 1061484247baafae1c19ce6101adf5d4180d72e2 Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Tue, 13 Oct 2020 00:14:14 +0200 Subject: [PATCH] Update --- Private/ConvertTo-XMLGenericPublicKey.ps1 | 80 ++++++++++++++++------- Public/Invoke-GPOZaurr.ps1 | 15 ++++- Public/Save-GPOZaurrFiles.ps1 | 4 ++ 3 files changed, 73 insertions(+), 26 deletions(-) diff --git a/Private/ConvertTo-XMLGenericPublicKey.ps1 b/Private/ConvertTo-XMLGenericPublicKey.ps1 index 275b2aa..462d297 100644 --- a/Private/ConvertTo-XMLGenericPublicKey.ps1 +++ b/Private/ConvertTo-XMLGenericPublicKey.ps1 @@ -2,11 +2,11 @@ function ConvertTo-XMLGenericPublicKey { [cmdletBinding()] param( [PSCustomObject] $GPO, - [string[]] $Category + [string[]] $Category, + [switch] $SingleObject ) - $SkipNames = ('Name', 'LocalName', 'NamespaceURI', 'Prefix', 'NodeType', 'ParentNode', 'OwnerDocument', 'IsEmpty', 'Attributes', 'HasAttributes', 'SchemaInfo', 'InnerXml', 'InnerText', 'NextSibling', 'PreviousSibling', 'ChildNodes', 'FirstChild', 'LastChild', 'HasChildNodes', 'IsReadOnly', 'OuterXml', 'BaseURI', 'PreviousText') - foreach ($Setting in $GPO.DataSet) { + if ($SingleObject) { $CreateGPO = [ordered]@{ DisplayName = $GPO.DisplayName DomainName = $GPO.DomainName @@ -14,23 +14,57 @@ function ConvertTo-XMLGenericPublicKey { GpoType = $GPO.GpoType #GpoCategory = $GPOEntry.GpoCategory #GpoSettings = $GPOEntry.GpoSettings + Count = 0 + Settings = $null } - $SettingName = $Setting.Name -split ":" - $CreateGPO['CreatedTime'] = $GPO.CreatedTime # : 06.06.2020 18:03:36 - $CreateGPO['ModifiedTime'] = $GPO.ModifiedTime # : 17.06.2020 16:08:10 - $CreateGPO['ReadTime'] = $GPO.ReadTime # : 13.08.2020 10:15:37 - $CreateGPO['SecurityDescriptor'] = $GPO.SecurityDescriptor # : SecurityDescriptor - $CreateGPO['FilterDataAvailable'] = $GPO.FilterDataAvailable # : True + [Array] $CreateGPO['Settings'] = foreach ($Setting in $GPO.DataSet) { + $SettingName = $Setting.Name -split ":" + $MySettings = [ordered] @{ + CreatedTime = $GPO.CreatedTime # : 06.06.2020 18:03:36 + ModifiedTime = $GPO.ModifiedTime # : 17.06.2020 16:08:10 + ReadTime = $GPO.ReadTime # : 13.08.2020 10:15:37 + SecurityDescriptor = $GPO.SecurityDescriptor # : SecurityDescriptor + FilterDataAvailable = $GPO.FilterDataAvailable # : True + } + $Name = $SettingName[1] + #$Name = Format-ToTitleCase -Text $Setting.Name -RemoveWhiteSpace -RemoveChar ',', '-', "'", '\(', '\)', ':' + $MySettings['Name'] = $Name # $Setting.Name - $Name = $SettingName[1] - #$Name = Format-ToTitleCase -Text $Setting.Name -RemoveWhiteSpace -RemoveChar ',', '-', "'", '\(', '\)', ':' - $CreateGPO['Name'] = $Name # $Setting.Name - #$CreateGPO['GPOSettingOrder'] = $Setting.GPOSettingOrder + ConvertTo-XMLNested -CreateGPO $MySettings -Setting $Setting -SkipNames $SkipNames #-Name $Name + [PSCustomObject] $MySettings + } - #foreach ($Property in ($Setting.Properties | Get-Member -MemberType Properties).Name) { + $CreateGPO['Count'] = $CreateGPO['Settings'].Count + $CreateGPO['Linked'] = $GPO.Linked + $CreateGPO['LinksCount'] = $GPO.LinksCount + $CreateGPO['Links'] = $GPO.Links + [PSCustomObject] $CreateGPO + } else { + foreach ($Setting in $GPO.DataSet) { + $CreateGPO = [ordered]@{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.GUID + GpoType = $GPO.GpoType + #GpoCategory = $GPOEntry.GpoCategory + #GpoSettings = $GPOEntry.GpoSettings + } + $SettingName = $Setting.Name -split ":" + $CreateGPO['CreatedTime'] = $GPO.CreatedTime # : 06.06.2020 18:03:36 + $CreateGPO['ModifiedTime'] = $GPO.ModifiedTime # : 17.06.2020 16:08:10 + $CreateGPO['ReadTime'] = $GPO.ReadTime # : 13.08.2020 10:15:37 + $CreateGPO['SecurityDescriptor'] = $GPO.SecurityDescriptor # : SecurityDescriptor + $CreateGPO['FilterDataAvailable'] = $GPO.FilterDataAvailable # : True - ConvertTo-XMLNested -CreateGPO $CreateGPO -Setting $Setting -SkipNames $SkipNames #-Name $Name - <# + $Name = $SettingName[1] + #$Name = Format-ToTitleCase -Text $Setting.Name -RemoveWhiteSpace -RemoveChar ',', '-', "'", '\(', '\)', ':' + $CreateGPO['Name'] = $Name # $Setting.Name + #$CreateGPO['GPOSettingOrder'] = $Setting.GPOSettingOrder + + #foreach ($Property in ($Setting.Properties | Get-Member -MemberType Properties).Name) { + + ConvertTo-XMLNested -CreateGPO $CreateGPO -Setting $Setting -SkipNames $SkipNames #-Name $Name + <# $Properties = $Setting.PSObject.Properties.Name | Where-Object { $_ -notin $SkipNames } foreach ($Property in $Properties) { If ($Property -eq 'Value') { @@ -62,13 +96,11 @@ function ConvertTo-XMLGenericPublicKey { } } #> - - - $CreateGPO['Filters'] = $Setting.Filters - - $CreateGPO['Linked'] = $GPO.Linked - $CreateGPO['LinksCount'] = $GPO.LinksCount - $CreateGPO['Links'] = $GPO.Links - [PSCustomObject] $CreateGPO + $CreateGPO['Filters'] = $Setting.Filters + $CreateGPO['Linked'] = $GPO.Linked + $CreateGPO['LinksCount'] = $GPO.LinksCount + $CreateGPO['Links'] = $GPO.Links + [PSCustomObject] $CreateGPO + } } } \ No newline at end of file diff --git a/Public/Invoke-GPOZaurr.ps1 b/Public/Invoke-GPOZaurr.ps1 index 4af87c3..4301578 100644 --- a/Public/Invoke-GPOZaurr.ps1 +++ b/Public/Invoke-GPOZaurr.ps1 @@ -50,7 +50,9 @@ [Parameter(ParameterSetName = 'Default')] [Parameter(ParameterSetName = 'Local')] - [switch] $SkipCleanup + [switch] $SkipCleanup, + + [switch] $Extended ) if ($Type.Count -eq 0) { $Type = $Script:GPODitionary.Keys @@ -219,9 +221,18 @@ #$Output['PoliciesTotal'] = $Output.Reports.Policies.PolicyCategory | Group-Object | Select-Object Name, Count | Sort-Object -Property Count -Descending if (-not $SkipCleanup) { + Write-Verbose "Invoke-GPOZaurr - Cleaning up output" Remove-EmptyValue -Hashtable $Output -Recursive } - return $Output + if ($Extended) { + $Output + } else { + if ($Output.Reports) { + $Output.Reports + } else { + Write-Warning "Invoke-GPOZaurr - There was no data output for requested types." + } + } } [scriptblock] $SourcesAutoCompleter = { diff --git a/Public/Save-GPOZaurrFiles.ps1 b/Public/Save-GPOZaurrFiles.ps1 index 8416766..8c682db 100644 --- a/Public/Save-GPOZaurrFiles.ps1 +++ b/Public/Save-GPOZaurrFiles.ps1 @@ -17,8 +17,12 @@ } } $null = New-Item -ItemType Directory -Path $GPOPath -Force + Write-Verbose "Save-GPOZaurrFiles - Gathering GPO data" + $Count = 0 $GPOs = Get-GPOZaurrAD -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation foreach ($GPO in $GPOS) { + $Count++ + Write-Verbose "Save-GPOZaurrFiles - Processing GPO ($Count/$($GPOS.Count)) $($GPO.DomainName) | $($GPO.DisplayName)" $XMLContent = Get-GPOReport -ID $GPO.Guid -ReportType XML -Domain $GPO.DomainName $GPODOmainFolder = [io.path]::Combine($GPOPath, $GPO.DomainName) if (-not (Test-Path -Path $GPODOmainFolder)) {