From 4f4fddddaef3cea0f8dfbab8116412109ec8c94a Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Wed, 20 Nov 2024 21:50:02 +0100 Subject: [PATCH] Add support for RestrcitedGroups #68 --- Private/ConvertTo-XMLRestrictedGroups.ps1 | 77 +++++++++++++++++++++++ Private/Script.GPODictionary.ps1 | 17 ++++- Public/Invoke-GPOZaurrContent.ps1 | 8 ++- 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 Private/ConvertTo-XMLRestrictedGroups.ps1 diff --git a/Private/ConvertTo-XMLRestrictedGroups.ps1 b/Private/ConvertTo-XMLRestrictedGroups.ps1 new file mode 100644 index 0000000..abfb214 --- /dev/null +++ b/Private/ConvertTo-XMLRestrictedGroups.ps1 @@ -0,0 +1,77 @@ +function ConvertTo-XMLRestrictedGroups { + [cmdletBinding()] + param( + [PSCustomObject] $GPO, + [switch] $SingleObject + ) + if ($SingleObject) { + $CreateGPO = [ordered]@{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.GUID + GpoType = $GPO.GpoType + #GpoCategory = $GPOEntry.GpoCategory + #GpoSettings = $GPOEntry.GpoSettings + Count = 0 + Settings = $null + } + [Array] $CreateGPO['Settings'] = foreach ($Script in $GPO.DataSet) { + $Members = foreach ($Member in $Group.Member) { + if ($($Member.SID.'#text')) { + "$($Member.Name.'#text') ($($Member.SID.'#text'))" + } else { + $Member.Name.'#text' + } + } + $MemberOf = foreach ($Member in $Group.MemberOf) { + if ($($Member.SID.'#text')) { + "$($Member.Name.'#text') ($($Member.SID.'#text'))" + } else { + $Member.Name.'#text' + } + } + [PSCustomObject]@{ + GroupName = $Group.GroupName.Name + GroupSID = $Group.GroupName.SID.'#text' + Members = $Members -join ', ' + MembersOf = $MemberOf -join ', ' + } + } + $CreateGPO['DataCount'] = $CreateGPO['Settings'].Count + $CreateGPO['Linked'] = $GPO.Linked + $CreateGPO['LinksCount'] = $GPO.LinksCount + $CreateGPO['Links'] = $GPO.Links + [PSCustomObject] $CreateGPO + } else { + foreach ($Group in $GPO.DataSet) { + $Members = foreach ($Member in $Group.Member) { + if ($($Member.SID.'#text')) { + "$($Member.Name.'#text') ($($Member.SID.'#text'))" + } else { + $Member.Name.'#text' + } + } + $MemberOf = foreach ($Member in $Group.MemberOf) { + if ($($Member.SID.'#text')) { + "$($Member.Name.'#text') ($($Member.SID.'#text'))" + } else { + $Member.Name.'#text' + } + } + $CreateGPO = [ordered]@{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.GUID + GpoType = $GPO.GpoType + GroupName = $Group.GroupName.Name.'#text' + GroupSID = $Group.GroupName.SID.'#text' + Members = $Members -join ', ' + MembersOf = $MemberOf -join ', ' + } + $CreateGPO['Linked'] = $GPO.Linked + $CreateGPO['LinksCount'] = $GPO.LinksCount + $CreateGPO['Links'] = $GPO.Links + [PSCustomObject] $CreateGPO + } + } +} \ No newline at end of file diff --git a/Private/Script.GPODictionary.ps1 b/Private/Script.GPODictionary.ps1 index e440b16..5c1ace7 100644 --- a/Private/Script.GPODictionary.ps1 +++ b/Private/Script.GPODictionary.ps1 @@ -380,7 +380,7 @@ ConvertTo-XMLGenericPolicy -GPO $GPO -Category 'FSLogix' -SingleObject } } - Firefox = @{ + Firefox = @{ Types = @( @{ Category = 'RegistrySettings' @@ -974,6 +974,21 @@ ConvertTo-XMLGenericPolicy -GPO $GPO -Category 'Windows Components/Remote Desktop Services*' -SingleObject } } + RestrictedGroups = @{ + Types = @( + @{ + Category = 'SecuritySettings' + Settings = 'RestrictedGroups' + } + ) + GPOPath = 'Policies -> Windows Settings -> Security Settings -> Restricted Groups' + Code = { + ConvertTo-XMLRestrictedGroups -GPO $GPO + } + CodeSingle = { + ConvertTo-XMLRestrictedGroups -GPO $GPO -SingleObject + } + } RSSFeeds = @{ Types = @( @{ diff --git a/Public/Invoke-GPOZaurrContent.ps1 b/Public/Invoke-GPOZaurrContent.ps1 index 96d88ac..eda4046 100644 --- a/Public/Invoke-GPOZaurrContent.ps1 +++ b/Public/Invoke-GPOZaurrContent.ps1 @@ -156,13 +156,17 @@ Get-GPOZaurrAD -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation -GPOName $Name } foreach ($GUID in $GPOGUID) { - Get-GPOZaurrAD -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation -GPOGUID $GUID + Get-GPOZaurrAD -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation -GPOGuid $GUID } ) } else { Write-Verbose "Invoke-GPOZaurrContent - Query AD for GPOs" [Array] $GPOs = Get-GPOZaurrAD -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation } + if ($GPOs.Count -eq 0) { + Write-Warning "Invoke-GPOZaurrContent - No GPOs found. Exiting." + return + } # This caches single reports. $TemporaryCachedSingleReports = [ordered] @{} $TemporaryCachedSingleReports['ReportsSingle'] = [ordered] @{} @@ -171,7 +175,7 @@ $Output['Reports'] = [ordered] @{} $Output['CategoriesFull'] = [ordered] @{} - $ForestInformation = Get-WinADForestDetails -PreferWritable -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation + $ForestInformation = Get-WinADForestDetails -PreferWritable -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation Write-Verbose "Invoke-GPOZaurrContent - Loading GPO Report to Categories" $CountGPO = 0