From 58d94edac097a1bd8ea55168217b6b0649274207 Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sun, 2 Aug 2020 00:32:04 +0200 Subject: [PATCH] Great policy, with update for ListBox --- Private/ConvertTo-XMLGenericPolicy.ps1 | 112 +++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 Private/ConvertTo-XMLGenericPolicy.ps1 diff --git a/Private/ConvertTo-XMLGenericPolicy.ps1 b/Private/ConvertTo-XMLGenericPolicy.ps1 new file mode 100644 index 0000000..07e79ff --- /dev/null +++ b/Private/ConvertTo-XMLGenericPolicy.ps1 @@ -0,0 +1,112 @@ +function ConvertTo-XMLGenericPolicy { + [cmdletBinding()] + param( + [PSCustomObject] $GPO, + [string[]] $Category + ) + $CreateGPO = [ordered]@{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.GUID + GpoType = $GPO.GpoType + #GpoCategory = $GPOEntry.GpoCategory + #GpoSettings = $GPOEntry.GpoSettings + } + $UsedNames = [System.Collections.Generic.List[string]]::new() + + [Array] $Policies = foreach ($Cat in $Category) { + $GPO.DataSet | Where-Object { $_.Category -like $Cat } + } + #if ($GPO.DataSet.Category -like $Category) { + if ($Policies.Count -gt 0) { + foreach ($Policy in $Policies) { + #if ($Policy.Category -notlike $Category) { + # We check again for Category because one GPO can have multiple categories + # First check checks GPO globally, + # continue + #} + $Name = Format-ToTitleCase -Text $Policy.Name -RemoveWhiteSpace -RemoveChar ',', '-', "'", '\(', '\)', ':' + $CreateGPO[$Name] = $Policy.State + + foreach ($Setting in @('DropDownList', 'Numeric', 'EditText', 'Text', 'CheckBox', 'ListBox')) { + if ($Policy.$Setting) { + foreach ($Value in $Policy.$Setting) { + if ($Value.Name) { + $SubName = Format-ToTitleCase -Text $Value.Name -RemoveWhiteSpace -RemoveChar ',', '-', "'", '\(', '\)', ':' + $SubName = -join ($Name, $SubName) + if ($SubName -notin $UsedNames) { + $UsedNames.Add($SubName) + } else { + $TimesUsed = $UsedNames | Group-Object | Where-Object { $_.Name -eq $SubName } + $NumberToUse = $TimesUsed.Count + 1 + # We add same name 2nd and 3rd time to make sure we count properly + $UsedNames.Add($SubName) + # We now build property name based on amnount of times + $SubName = -join ($SubName, "$NumberToUse") + } + if ($Value.Value -is [string]) { + $CreateGPO["$SubName"] = $Value.Value + } elseif ($Value.Value -is [System.Xml.XmlElement]) { + + <# + if ($null -eq $Value.Value.Name) { + # Shouldn't happen but lets see + Write-Verbose $Value + } else { + $CreateGPO["$SubName"] = $Value.Value.Name + } + + #> + if ($Value.Value.Element) { + $CreateGPO["$SubName"] = $Value.Value.Element.Data -join '; ' + } elseif ($null -eq $Value.Value.Name) { + # Shouldn't happen but lets see + Write-Verbose "Tracking $Value" + } else { + $CreateGPO["$SubName"] = $Value.Value.Name + } + + } elseif ($Value.State) { + $CreateGPO["$SubName"] = $Value.State + } elseif ($null -eq $Value.Value) { + # This is most likely Setting 'Text + # Do nothing, usually it's just a text to display + #Write-Verbose "Skipping value for display because it's empty. Name: $($Value.Name)" + } else { + # shouldn't happen + Write-Verbose $Value + } + } + } + } + } + } + $CreateGPO['Linked'] = $GPO.Linked + $CreateGPO['LinksCount'] = $GPO.LinksCount + $CreateGPO['Links'] = $GPO.Links + [PSCustomObject] $CreateGPO + #} + } +} + +<# ListBox - $Value +Name : Items to run at logon +State : Enabled +ExplicitValue : false +Additive : false +ValuePrefix : +Value : Value + +ListBox - $Value.Value + +Element +------- +Element + +ListBox - $Value.Value.Element + +Data +---- +C:\Program Files (x86)\NetPhone Client\NetPhone Client.exe + +#> \ No newline at end of file