More work on Find-GPO

This commit is contained in:
Przemyslaw Klys
2020-06-27 17:44:25 +02:00
parent d94bf27669
commit 99d489290d
3 changed files with 64 additions and 27 deletions
+31
View File
@@ -0,0 +1,31 @@
function Get-XMLGPOTypes {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter = [System.Environment]::NewLine,
[switch] $FullObjects
)
$Types = [ordered] @{
User = [System.Collections.Generic.List[string]]::new()
Computer = [System.Collections.Generic.List[string]]::new()
All = $null
}
[Array] $TypesReturn = foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension) {
foreach ($ExtensionType in $GPOOutput.$Type.ExtensionData.Extension) {
$GPOSettingType = ($ExtensionType.type -split ':')[1]
# add to hashtable
$Types["$Type"].Add($GPOSettingType)
# add to array
$GPOSettingType
}
}
}
$Types.Computer = $Types.Computer | Sort-Object -Unique
$Types.User = $Types.User | Sort-Object -Unique
$Types.All = $TypesReturn | Sort-Object -Unique
$Types
}
+20 -26
View File
@@ -10,34 +10,28 @@
foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension) {
foreach ($ExtensionType in $GPOOutput.$Type.ExtensionData.Extension) {
$GPOSettingType = ($ExtensionType.type -split ':')[1]
Write-Warning $GPOSettingType
foreach ($Key in $ExtensionType.Account) {
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
Name = $Key.Name
Type = $Key.Type
SettingNumber = $Key.SettingNumber
SettingBoolean = if ($Key.SettingBoolean -eq 'true') { $true } elseif ($Key.SettingBoolean -eq 'false') { $false } else { $null }
$GPOSettingTypeSplit = ($ExtensionType.type -split ':')
$KeysToLoop = $ExtensionType | Get-Member -MemberType Properties | Where-Object { $_.Name -notin 'type', $GPOSettingTypeSplit[0] }
foreach ($Keys in $KeysToLoop.Name) {
foreach ($Key in $ExtensionType.$Keys) {
$Template = [ordered] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
GpoSubType = $GPOSettingTypeSplit[1]
}
$Properties = ($Key | Get-Member -MemberType Properties).Name
foreach ($Property in $Properties) {
$Template["$Property"] = $Key.$Property
}
[PSCustomObject] $Template
}
}
}
}
}
}
<#
q1 : http://www.microsoft.com/GroupPolicy/Settings/Security
type : q1:SecuritySettings
Account : {ClearTextPassword, LockoutBadCount, LockoutDuration, MaximumPasswordAge...}
SecurityOptions : SecurityOptions
SystemServices : SystemServices
#>
#$GPOSettingType = ($ExtensionType.type -split ':')[1]
}
+13 -1
View File
@@ -57,7 +57,7 @@
}
$Output = [ordered] @{}
foreach ($T in $Type) {
$Output[$T] = [System.Collections.Generic.List[PSCustomObject]]::new()
# $Output[$T] = [System.Collections.Generic.List[PSCustomObject]]::new()
}
foreach ($GPO in $GPOs) {
if ($GPOPath) {
@@ -77,6 +77,18 @@
UserPolicies = $GPOOutput.GPO.User.ExtensionData.Name -join ", "
}
#>
$GPOStoredTypes = Get-XMLGPOTypes -GPOOutput $GPOOutput.GPO
[Array] $Data = Get-XMLStandard -GPO $GPO -GPOOutput $GPOOutput.GPO -Splitter $Splitter -FullObjects:$FullObjects
foreach ($D in $Data) {
if (-not $Output["$($D.GpoSubType)"]) {
$Output["$($D.GpoSubType)"] = [System.Collections.Generic.List[PSCustomObject]]::new()
}
$Output["$($D.GpoSubType)"].Add($D)
}
continue
if ($Type -contains 'RegistrySettings') {
[Array] $Data = Get-XMLRegistrySettings -GPO $GPO -GPOOutput $GPOOutput.GPO -Splitter $Splitter -FullObjects:$FullObjects
foreach ($D in $Data) {