Added Find-GPO WIP

This commit is contained in:
Przemyslaw Klys
2020-06-27 12:45:23 +02:00
parent 2286f0cb0b
commit 570b1cbc83
12 changed files with 368 additions and 62 deletions
+38
View File
@@ -0,0 +1,38 @@
function Get-LinksFromXML {
[cmdletBinding()]
param(
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter,
[switch] $FullObjects
)
$Links = [ordered] @{
Linked = $null
LinksCount = $null
Links = $null
}
if ($GPOOutput.LinksTo) {
$Links.Linked = $true
$Links.LinksCount = ([Array] $GPOOutput.LinksTo).Count
$Links.Links = foreach ($Link in $GPOOutput.LinksTo) {
if ($FullObjects) {
[PSCustomObject] @{
Path = $Link.SOMPath
Enabled = if ($Link.Enabled -eq 'true') { $true } else { $false }
NoOverride = if ($Link.NoOverride -eq 'true') { $true } else { $false }
}
} else {
if ($Link.Enabled) {
$Link.SOMPath
}
}
}
if ($Splitter) {
$Links.Links = $Links.Links -join $Splitter
}
} else {
$Links.Linked = $false
$Links.LinksCount = 0
$Links.Links = $null
}
[PSCustomObject] $Links
}
+52 -48
View File
@@ -2,57 +2,61 @@
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[System.Xml.XmlElement[]] $GPOOutput
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter = [System.Environment]::NewLine,
[switch] $FullObjects
)
if ($GPOOutput.LinksTo) {
$Linked = $true
$LinksCount = ([Array] $GPOOutput.LinksTo).Count
} else {
$Linked = $false
$LinksCount = 0
}
$LinksInformation = Get-LinksFromXML -GPOOutput $GPOOutput -Splitter $Splitter -FullObjects:$FullObjects
foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension.RegistrySettings) {
foreach ($Key in $GPOOutput.$Type.ExtensionData.Extension.RegistrySettings.Registry) {
#$Key
<#
clsid : {9CD4B2F4-923D-47f5-A062-E897DD1DAD50}
name : AutoAdminLogon
status : AutoAdminLogon
image : 7
changed : 2013-02-06 09:57:45
uid : {23AD1B6F-0D90-49B5-926D-AAA6E1E2F4B3}
GPOSettingOrder : 1
Properties : Properties
Filters :
#>
<# $Key.properties
action : U
displayDecimal : 0
default : 0
hive : HKEY_LOCAL_MACHINE
key : SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
name : AutoAdminLogon
type : REG_SZ
value : 1
Values :
#>
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $Linked
LinksCount = $LinksCount
Changed = [DateTime] $Key.changed
GPOSettingOrder = $Key.GPOSettingOrder
hive = $Key.Properties.hive #: HKEY_LOCAL_MACHINE
key = $Key.Properties.key #: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
name = $Key.Properties.name #: AutoAdminLogon
type = $Key.Properties.type #: REG_SZ
value = $Key.Properties.value #
Filters = $Key.Filters
if ($GPOOutput.$Type.ExtensionData.Extension) {
foreach ($ExtensionType in $GPOOutput.$Type.ExtensionData.Extension) {
if ($ExtensionType.RegistrySettings.Registry.Properties.Key -ne 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon') {
continue
}
$Autologon = [ordered] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
AutoAdminLogon = $null
DefaultDomainName = $null
DefaultUserName = $null
DefaultPassword = $null
}
foreach ($Key in $ExtensionType.RegistrySettings.Registry) {
if ($Key.Properties.key -eq 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon') {
<#
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $Linked
LinksCount = $LinksCount
GpoType = $Type
Changed = [DateTime] $Key.changed
GPOSettingOrder = $Key.GPOSettingOrder
hive = $Key.Properties.hive #: HKEY_LOCAL_MACHINE
key = $Key.Properties.key #: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
name = $Key.Properties.name #: AutoAdminLogon
type = $Key.Properties.type #: REG_SZ
value = $Key.Properties.value #
Filters = $Key.Filters
}
#>
if ($Key.Properties.Name -eq 'AutoAdminLogon') {
$Autologon['AutoAdminLogon'] = [bool] $Key.Properties.value
} elseif ($Key.Properties.Name -eq 'DefaultDomainName') {
$Autologon['DefaultDomainName'] = $Key.Properties.value
} elseif ($Key.Properties.Name -eq 'DefaultUserName') {
$Autologon['DefaultUserName'] = $Key.Properties.value
} elseif ($Key.Properties.Name -eq 'DefaultPassword') {
$Autologon['DefaultPassword'] = $Key.Properties.value
}
}
}
[PSCustomObject] $Autologon
}
}
}
+11 -14
View File
@@ -1,17 +1,12 @@
function Get-XMLLocalUserGroups {
function Get-XMLLocalUserGroups {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[System.Xml.XmlElement[]] $GPOOutput
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter = [System.Environment]::NewLine,
[switch] $FullObjects
)
if ($GPOOutput.LinksTo) {
$Linked = $true
$LinksCount = ([Array] $GPOOutput.LinksTo).Count
} else {
$Linked = $false
$LinksCount = 0
}
$LinksInformation = Get-LinksFromXML -GPOOutput $GPOOutput -Splitter $Splitter -FullObjects:$FullObjects
foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension.LocalUsersAndGroups) {
foreach ($NestedType in @('User', 'Group')) {
@@ -24,8 +19,9 @@ function Get-XMLLocalUserGroups {
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $Linked
LinksCount = $LinksCount
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
Name = $Entry.name
Changed = [DateTime] $Entry.changed
@@ -59,8 +55,9 @@ function Get-XMLLocalUserGroups {
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $Linked
LinksCount = $LinksCount
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
Name = $Entry.name
Changed = [DateTime] $Entry.changed
+41
View File
@@ -0,0 +1,41 @@
function Get-XMLRegistryPolicies {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter = [System.Environment]::NewLine,
[switch] $FullObjects
)
$LinksInformation = Get-LinksFromXML -GPOOutput $GPOOutput -Splitter $Splitter -FullObjects:$FullObjects
foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension) {
foreach ($ExtensionType in $GPOOutput.$Type.ExtensionData.Extension) {
foreach ($Key in $ExtensionType.Policy) {
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
PolicyName = $Key.Name
PolicyState = $Key.State
PolicyCategory = $Key.Category
PolicySupported = $Key.Supported
PolicyExplain = $Key.Explain
PolicyCheckBox = $Key.CheckBox
PolicyText = $Key.Text
DropDownList = $Key.DropDownList
PolicyEditText = $Key.EditText
<#
Name State Value
---- ----- -----
Target group name for this computer Enabled de00_wsus3_measuring_devices
#>
}
}
}
}
}
}
+35
View File
@@ -0,0 +1,35 @@
function Get-XMLRegistrySettings {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter = [System.Environment]::NewLine,
[switch] $FullObjects
)
$LinksInformation = Get-LinksFromXML -GPOOutput $GPOOutput -Splitter $Splitter -FullObjects:$FullObjects
foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension) {
foreach ($ExtensionType in $GPOOutput.$Type.ExtensionData.Extension) {
foreach ($Key in $ExtensionType.RegistrySettings.Registry) {
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
Changed = [DateTime] $Key.changed
GPOSettingOrder = $Key.GPOSettingOrder
Hive = $Key.Properties.hive #: HKEY_LOCAL_MACHINE
Key = $Key.Properties.key #: SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Name = $Key.Properties.name #: AutoAdminLogon
Type = $Key.Properties.type #: REG_SZ
Value = $Key.Properties.value #
Filters = $Key.Filters
}
}
}
}
}
}
+49
View File
@@ -0,0 +1,49 @@
function Get-XMLScripts {
[cmdletBinding()]
param(
[PSCustomObject] $GPO,
[System.Xml.XmlElement[]] $GPOOutput,
[string] $Splitter = [System.Environment]::NewLine,
[switch] $FullObjects
)
$LinksInformation = Get-LinksFromXML -GPOOutput $GPOOutput -Splitter $Splitter -FullObjects:$FullObjects
foreach ($Type in @('User', 'Computer')) {
if ($GPOOutput.$Type.ExtensionData.Extension) {
foreach ($ExtensionType in $GPOOutput.$Type.ExtensionData.Extension) {
foreach ($Key in $ExtensionType.Script) {
if ($FullObjects) {
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
Command = $Key.Command
Parameters = $Key.Parameters
Type = $Key.Type
Order = $Key.Order
RunOrder = $Key.RunOrder
}
} else {
[PSCustomObject] @{
DisplayName = $GPO.DisplayName
DomainName = $GPO.DomainName
GUID = $GPO.Guid
Linked = $LinksInformation.Linked
LinksCount = $LinksInformation.LinksCount
Links = $LinksInformation.Links
GpoType = $Type
Command = $Key.Command
Parameters = $Key.Parameters
type = $Key.Type
Order = $Key.Order
RunOrder = $Key.RunOrder
}
}
}
}
}
}
}