From e514deca08f5b7e36f281546b7c680a03b11ff37 Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Thu, 16 Jul 2020 00:03:54 +0200 Subject: [PATCH] Update --- Private/Get-XMLOutput.ps1 | 72 +++++++++++++++++++++++++++ Private/Script.GPODictionary.ps1 | 84 ++++++++++++++++++-------------- Public/Invoke-GPOZaurr.ps1 | 44 +++++++++++------ 3 files changed, 147 insertions(+), 53 deletions(-) create mode 100644 Private/Get-XMLOutput.ps1 diff --git a/Private/Get-XMLOutput.ps1 b/Private/Get-XMLOutput.ps1 new file mode 100644 index 0000000..c84cdd6 --- /dev/null +++ b/Private/Get-XMLOutput.ps1 @@ -0,0 +1,72 @@ +function Get-XMLOutput { + [cmdletBinding()] + param( + [PSCustomObject] $GPO, + [System.Xml.XmlElement[]] $GPOOutput, + [string] $Splitter, + [switch] $FullObjects + ) + $LinksInformation = Get-LinksFromXML -GPOOutput $GPOOutput -Splitter $Splitter -FullObjects:$FullObjects + foreach ($GpoType in @('User', 'Computer')) { + if ($GPOOutput.$GpoType.ExtensionData.Extension) { + foreach ($ExtensionType in $GPOOutput.$GpoType.ExtensionData.Extension) { + # It's possible that one of the ExtensionType records has value null. Weird but happend. + if ($ExtensionType) { + $GPOSettingTypeSplit = ($ExtensionType.type -split ':') + try { + $KeysToLoop = $ExtensionType | Get-Member -MemberType Properties -ErrorAction Stop | Where-Object { $_.Name -notin 'type', $GPOSettingTypeSplit[0] -and $_.Name -notin @('Blocked') } + } catch { + Write-Warning "Get-XMLStandard - things went sideways $($_.Exception.Message)" + continue + } + foreach ($GpoSettings in $KeysToLoop.Name) { + $Template = [ordered] @{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.Guid + GpoType = $GpoType + GpoCategory = $GPOSettingTypeSplit[1] + GpoSettings = $GpoSettings + } + [PSCustomObject] $Template + } + continue + + foreach ($GpoSettings in $KeysToLoop.Name) { + foreach ($Key in $ExtensionType.$GpoSettings) { + $Template = [ordered] @{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.Guid + GpoType = $GpoType + GpoCategory = $GPOSettingTypeSplit[1] + GpoSettings = $GpoSettings + } + try { + $Properties = ($Key | Get-Member -MemberType Properties -ErrorAction Stop).Name + } catch { + Write-Warning "Get-XMLStandard - things went sideways 1 $($_.Exception.Message)" + $Properties = $null + } + foreach ($Property in $Properties) { + $Template["$Property"] = $Key.$Property + } + $Template['Linked'] = $LinksInformation.Linked + $Template['LinksCount'] = $LinksInformation.LinksCount + $Template['Links'] = $LinksInformation.Links + <# + $Template['IncludeComments'] = $GPOOutput.IncludeComments # : true #: true + $Template['CreatedTime'] = $GPOOutput.CreatedTime # : 2020-06-17T11:23:22 #: 2020-06-17T11:23:22 + $Template['ModifiedTime'] = $GPOOutput.ModifiedTime # : 2020-06-28T15:49:52 #: 2020-06-28T15:49:52 + $Template['ReadTime'] = $GPOOutput.ReadTime # : 2020-06-28T16:14:09.2209011Z #: 2020-06-28T16:14:09.2209011Z + $Template['SecurityDescriptor'] = $GPOOutput.SecurityDescriptor # : SecurityDescriptor #: SecurityDescriptor + $Template['FilterDataAvailable'] = $GPOOutput.FilterDataAvailable # : true #: true + #> + [PSCustomObject] $Template + } + } + } + } + } + } +} \ No newline at end of file diff --git a/Private/Script.GPODictionary.ps1 b/Private/Script.GPODictionary.ps1 index 9bd0389..6547028 100644 --- a/Private/Script.GPODictionary.ps1 +++ b/Private/Script.GPODictionary.ps1 @@ -50,39 +50,40 @@ ConvertTo-XMLEventLog -GPO $GPO } } - <# - LocalUsersAndGroups = [ordered] @{ - Category = 'LugsSettings' - Settings = 'LocalUsersAndGroups' - Code = { + + LocalUsersAndGroups = [ordered] @{ + Category = 'LugsSettings' + Settings = 'LocalUsersAndGroups' + Code = { #ConvertTo-LocalUserAndGroups -GPOList $GPOList ConvertTo-XMLLocalUserAndGroups -GPO $GPO } - } - #> - <# - Policies = @{ - Category = 'RegistrySettings' - Settings = 'Policy' - Code = { - ConvertTo-Policies -GPOList $GPOList + CodeSingle = { + #ConvertTo-EventLog -GPOList $GPOList + ConvertTo-XMLLocalUserAndGroups -GPO $GPO -SingleObject } } - RegistrySettings = [ordered] @{ - Category = 'RegistrySettings' - Settings = 'RegistrySettings' - Code = { - ConvertTo-RegistrySettings -GPOList $GPOList + + Policies = @{ + Category = 'RegistrySettings' + Settings = 'Policy' + Code = { + ConvertTo-XMLPolicies -GPO $GPO + } + CodeSingle = { + ConvertTo-XMLPolicies -GPO $GPO -SingleObject } } - RegistrySettingsCollection = [ordered] @{ - Category = 'RegistrySettings' - Settings = 'RegistrySettings' - Code = { - ConvertTo-RegistrySettingsCollection -GPOList $GPOList + RegistrySettings = [ordered] @{ + Category = 'RegistrySettings' + Settings = 'RegistrySettings' + Code = { + ConvertTo-XMLRegistrySettings -GPO $GPO + } + CodeSingle = { + ConvertTo-XMLRegistrySettings -GPO $GPO -SingleObject } } - #> Scripts = [ordered] @{ Category = 'Scripts' Settings = 'Script' @@ -94,15 +95,18 @@ ConvertTo-XMLScripts -GPO $GPO -SingleObject } } - <# - SecurityOptions = [ordered] @{ - Category = 'SecuritySettings' - Settings = 'SecurityOptions' - Code = { - ConvertTo-SecurityOptions -GPOList $GPOList + SecurityOptions = [ordered] @{ + Category = 'SecuritySettings' + Settings = 'SecurityOptions' + Code = { + #ConvertTo-SecurityOptions -GPOList $GPOList + ConvertTo-XMLSecurityOptions -GPO $GPO + } + CodeSingle = { + #ConvertTo-SecurityOptions -GPOList $GPOList + ConvertTo-XMLSecurityOptions -GPO $GPO -SingleObject } } - #> SoftwareInstallation = [ordered] @{ Category = 'SoftwareInstallationSettings' Settings = 'MsiApplication' @@ -114,24 +118,30 @@ ConvertTo-XMLSoftwareInstallation -GPO $GPO -SingleObject } } - <# - SystemServices = [ordered] @{ + SystemServices = [ordered] @{ Description = '' GPOPath = 'Computer Configuration -> Policies -> Windows Settings -> Security Settings -> System Services' Category = 'SecuritySettings' Settings = 'SystemServices' Code = { - ConvertTo-SystemServices -GPOList $GPOList + # ConvertTo-SoftwareInstallation -GPOList $GPOList + ConvertTo-XMLSystemServices -GPO $GPO + } + CodeSingle = { + ConvertTo-XMLSystemServices -GPO $GPO -SingleObject } } - SystemServicesNT = [ordered] @{ + SystemServicesNT = [ordered] @{ Description = '' GPOPath = 'Computer Configuration -> Preferences -> Control Pannel Settings -> Services' Category = 'ServiceSettings' Settings = 'NTServices' Code = { - ConvertTo-SystemServicesNT -GPOList $GPOList + # ConvertTo-SoftwareInstallation -GPOList $GPOList + ConvertTo-XMLSystemServicesNT -GPO $GPO + } + CodeSingle = { + ConvertTo-XMLSystemServicesNT -GPO $GPO -SingleObject } } - #> } \ No newline at end of file diff --git a/Public/Invoke-GPOZaurr.ps1 b/Public/Invoke-GPOZaurr.ps1 index a6f3001..3de959e 100644 --- a/Public/Invoke-GPOZaurr.ps1 +++ b/Public/Invoke-GPOZaurr.ps1 @@ -100,31 +100,43 @@ $Output['CategoriesFull'] = $CachedCategories # Process Reporting $Output['Reports'] = [ordered] @{} - foreach ($Report in $Type) { - $Category = $Script:GPODitionary[$Report]['Category'] - $Settings = $Script:GPODitionary[$Report]['Settings'] - $CategorizedGPO = $CachedCategories[$Category][$Settings] - foreach ($GPO in $CategorizedGPO) { - if (-not $Output['Reports'][$Report]) { - $Output['Reports'][$Report] = [System.Collections.Generic.List[PSCustomObject]]::new() + if ($CachedCategories.Count -gt 0) { + foreach ($Report in $Type) { + $Category = $Script:GPODitionary[$Report]['Category'] + $Settings = $Script:GPODitionary[$Report]['Settings'] + + # Those are checks for making sure we have data to be even able to process it + if (-not $CachedCategories[$Category]) { + continue } - if ($SingleObject) { - if ($Script:GPODitionary[$Report]['CodeSingle']) { - $TranslatedGpo = Invoke-Command -ScriptBlock $Script:GPODitionary[$Report]['CodeSingle'] - $Output['Reports'][$Report].Add($TranslatedGpo) + if (-not $CachedCategories[$Category][$Settings]) { + continue + } + # Translation + $CategorizedGPO = $CachedCategories[$Category][$Settings] + foreach ($GPO in $CategorizedGPO) { + if (-not $Output['Reports'][$Report]) { + $Output['Reports'][$Report] = [System.Collections.Generic.List[PSCustomObject]]::new() } - } else { - if ($Script:GPODitionary[$Report]['Code']) { - $TranslatedGpo = Invoke-Command -ScriptBlock $Script:GPODitionary[$Report]['Code'] - $Output['Reports'][$Report].Add($TranslatedGpo) + $TranslatedGpo = $null + if ($SingleObject) { + if ($Script:GPODitionary[$Report]['CodeSingle']) { + $TranslatedGpo = Invoke-Command -ScriptBlock $Script:GPODitionary[$Report]['CodeSingle'] + } + } else { + if ($Script:GPODitionary[$Report]['Code']) { + $TranslatedGpo = Invoke-Command -ScriptBlock $Script:GPODitionary[$Report]['Code'] + } + } + foreach ($T in $TranslatedGpo) { + $Output['Reports'][$Report].Add($T) } } } } - return $Output foreach ($GPO in $GPOs) {