From 8b963c6b8291d145210fcdcb4e228e46f43a9755 Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Thu, 30 Jul 2020 21:58:28 +0200 Subject: [PATCH] Rewritten Autologon using Reports on Reports --- ...ConvertTo-XMLRegistryAutologonOnReport.ps1 | 49 +++++++++++++++++++ Private/Script.GPODictionary.ps1 | 15 ++++++ 2 files changed, 64 insertions(+) create mode 100644 Private/ConvertTo-XMLRegistryAutologonOnReport.ps1 diff --git a/Private/ConvertTo-XMLRegistryAutologonOnReport.ps1 b/Private/ConvertTo-XMLRegistryAutologonOnReport.ps1 new file mode 100644 index 0000000..1ca4c8c --- /dev/null +++ b/Private/ConvertTo-XMLRegistryAutologonOnReport.ps1 @@ -0,0 +1,49 @@ +function ConvertTo-XMLRegistryAutologonOnReport { + [cmdletBinding()] + param( + [PSCustomObject] $GPO + ) + $CreateGPO = [ordered]@{ + DisplayName = $GPO.DisplayName + DomainName = $GPO.DomainName + GUID = $GPO.GUID + GpoType = $GPO.GpoType + #GpoCategory = $GPOEntry.GpoCategory + #GpoSettings = $GPOEntry.GpoSettings + AutoAdminLogon = $null + DefaultDomainName = $null + DefaultUserName = $null + DefaultPassword = $null + DateChangedAutoAdminLogon = $null + DateChangedDefaultDomainName = $null + DateChangedDefaultUserName = $null + DateChangedDefaultPassword = $null + } + foreach ($Registry in $GPO.Settings) { + if ($Registry.Key -eq 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon') { + if ($Registry.Name -eq 'AutoAdminLogon') { + $CreateGPO['AutoAdminLogon'] = [bool] $Registry.value + $CreateGPO['DateChangedAutoAdminLogon'] = [DateTime] $Registry.changed + } elseif ($Registry.Name -eq 'DefaultDomainName') { + $CreateGPO['DefaultDomainName'] = $Registry.value + $CreateGPO['DateChangedDefaultDomainName'] = [DateTime] $Registry.changed + } elseif ($Registry.Name -eq 'DefaultUserName') { + $CreateGPO['DefaultUserName'] = $Registry.value + $CreateGPO['DateChangedDefaultUserName'] = [DateTime] $Registry.changed + } elseif ($Registry.Name -eq 'DefaultPassword') { + $CreateGPO['DefaultPassword'] = $Registry.value + $CreateGPO['DateChangedDefaultPassword'] = [DateTime] $Registry.changed + } + } + } + if ($null -ne $CreateGPO['AutoAdminLogon'] -or + $null -ne $CreateGPO['DefaultDomainName'] -or + $null -ne $CreateGPO['DefaultUserName'] -or + $null -ne $CreateGPO['DefaultPassword'] + ) { + $CreateGPO['Linked'] = $GPOEntry.Linked #: True + $CreateGPO['LinksCount'] = $GPOEntry.LinksCount #: 1 + $CreateGPO['Links'] = $GPOEntry.Links #: area1.local + [PSCustomObject] $CreateGPO + } +} \ No newline at end of file diff --git a/Private/Script.GPODictionary.ps1 b/Private/Script.GPODictionary.ps1 index f9d2698..0fb501e 100644 --- a/Private/Script.GPODictionary.ps1 +++ b/Private/Script.GPODictionary.ps1 @@ -30,18 +30,33 @@ } } Autologon = [ordered] @{ + # We want to process this based on other report called RegistrySettings + # This is because registry settings can be stored in Collections or nested within other registry settings + # The original function ConvertTo-XMLRegistryAutologon was processing it in limited ordered and potentially would skip some entries. + <# Types = @( @{ Category = 'RegistrySettings' Settings = 'RegistrySettings' } ) + #> + ByReports = @( + @{ + Report = 'RegistrySettings' + } + ) + <# Code = { ConvertTo-XMLRegistryAutologon -GPO $GPO } CodeSingle = { ConvertTo-XMLRegistryAutologon -GPO $GPO } + #> + CodeReport = { + ConvertTo-XMLRegistryAutologonOnReport -GPO $GPO + } } DriveMapping = [ordered] @{ Types = @(