From 97ffc8bfd50c6bf936529cefb02ff74cb2fa31ff Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sun, 28 Jun 2020 10:08:09 +0200 Subject: [PATCH] Update --- Examples/Example-29-FindGPO.ps1 | 2 +- Examples/Example-29-FindGPOFromDiskWork.ps1 | 25 ++++++ Examples/Example-29-FindGPOHtmlOutput.ps1 | 2 +- .../Example-29-FindGPOTranslationHelp.ps1 | 2 +- Examples/Example-29-FindGPOfromDisk.ps1 | 12 ++- GPOZaurr.psd1 | 4 +- Private/GpoTypes/SecurityOptions.ps1 | 77 +++++++++++++++++++ .../SecuritySettingsSecurityOptions.ps1 | 24 ------ Private/Invoke-GPOTranslation.ps1 | 11 +-- Private/Script.GPODictionary.ps1 | 7 +- Public/{Find-GPO.ps1 => Invoke-GPOZaurr.ps1} | 53 +++++++------ README.md | 2 +- 12 files changed, 154 insertions(+), 67 deletions(-) create mode 100644 Examples/Example-29-FindGPOFromDiskWork.ps1 create mode 100644 Private/GpoTypes/SecurityOptions.ps1 delete mode 100644 Private/GpoTypes/SecuritySettingsSecurityOptions.ps1 rename Public/{Find-GPO.ps1 => Invoke-GPOZaurr.ps1} (84%) diff --git a/Examples/Example-29-FindGPO.ps1 b/Examples/Example-29-FindGPO.ps1 index 50ad3e6..ba4a344 100644 --- a/Examples/Example-29-FindGPO.ps1 +++ b/Examples/Example-29-FindGPO.ps1 @@ -1,6 +1,6 @@ Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force -$Output = Find-GPO #-NoTranslation +$Output = Invoke-GPOZaurr #-NoTranslation New-HTML { foreach ($GPOCategory in $Output.Keys) { diff --git a/Examples/Example-29-FindGPOFromDiskWork.ps1 b/Examples/Example-29-FindGPOFromDiskWork.ps1 new file mode 100644 index 0000000..6c4002a --- /dev/null +++ b/Examples/Example-29-FindGPOFromDiskWork.ps1 @@ -0,0 +1,25 @@ +Import-Module "$PSScriptRoot\..\GPoZaurr.psd1" -Force + +# Use Save-GPOZaurrFiles -GPOPath $ENV:USERPROFILE\Desktop\GPOExport + +$OutputTranslation = Invoke-GPOZaurr -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExport' +$OutputTranslation | Format-Table +$Output = Invoke-GPOZaurr -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExport' -NoTranslation +$Output | Format-Table * + +#$Output.LugsSettings.LocalUsersAndGroups | Format-List * + +$GPOEntry = $Output.LugsSettings.LocalUsersAndGroups[0] + +$CreateGPO = @{} +foreach ($User in $GPOEntry.User) { + # $User | Format-Table + # $User.Properties | Format-Table +} + + +foreach ($Group in $GPOEntry.Group) { + #$Group | Format-Table + $Group.Properties | Format-Table + $Group.Properties.Members | Format-Table +} \ No newline at end of file diff --git a/Examples/Example-29-FindGPOHtmlOutput.ps1 b/Examples/Example-29-FindGPOHtmlOutput.ps1 index a1b89f4..67e12e7 100644 --- a/Examples/Example-29-FindGPOHtmlOutput.ps1 +++ b/Examples/Example-29-FindGPOHtmlOutput.ps1 @@ -2,5 +2,5 @@ # Use Save-GPOZaurrFiles -GPOPath $ENV:USERPROFILE\Desktop\GPOExport -$Output = Find-GPO -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExportTest' -NoTranslation +$Output = Invoke-GPOZaurr -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExportTest' -NoTranslation $Output | Format-Table * \ No newline at end of file diff --git a/Examples/Example-29-FindGPOTranslationHelp.ps1 b/Examples/Example-29-FindGPOTranslationHelp.ps1 index 69140b9..0ca1c4b 100644 --- a/Examples/Example-29-FindGPOTranslationHelp.ps1 +++ b/Examples/Example-29-FindGPOTranslationHelp.ps1 @@ -2,7 +2,7 @@ # This is purely for building GPO Dictionary, mostly for development needs to help asses what is there -$Output = Find-GPO -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExportTest' -NoTranslation +$Output = Invoke-GPOZaurr -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExportTest' -NoTranslation #$Output | Format-Table * $LookingFor = $Output | Select-GPOTranslation -Category 'SecuritySettings' -Settings 'UserRightsAssignment' diff --git a/Examples/Example-29-FindGPOfromDisk.ps1 b/Examples/Example-29-FindGPOfromDisk.ps1 index 8947ce9..f4135f9 100644 --- a/Examples/Example-29-FindGPOfromDisk.ps1 +++ b/Examples/Example-29-FindGPOfromDisk.ps1 @@ -2,16 +2,20 @@ # Use Save-GPOZaurrFiles -GPOPath $ENV:USERPROFILE\Desktop\GPOExport -$Output = Find-GPO -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExportTest' #-NoTranslation +$Output = Invoke-GPOZaurr -GPOPath 'C:\Support\GitHub\GpoZaurr\Ignore\GPOExportTest' #-NoTranslation $Output | Format-Table * New-HTML { foreach ($GPOCategory in $Output.Keys) { New-HTMLTab -Name $GPOCategory { - foreach ($GpoSettings in $Output.$GPOCategory.Keys) { - New-HTMLTab -Name $GpoSettings { - New-HTMLTable -DataTable $Output[$GPOCategory][$GpoSettings] -ScrollX -DisablePaging -AllProperties -Title $Key + if ($Output["$GPOCategory"] -is [System.Collections.IDictionary]) { + foreach ($GpoSettings in $Output["$GPOCategory"].Keys) { + New-HTMLTab -Name $GpoSettings { + New-HTMLTable -DataTable $Output[$GPOCategory][$GpoSettings] -ScrollX -DisablePaging -AllProperties -Title $Key + } } + } else { + New-HTMLTable -DataTable $Output[$GPOCategory] -ScrollX -DisablePaging -AllProperties -Title $Key } } } diff --git a/GPOZaurr.psd1 b/GPOZaurr.psd1 index 48fd107..8208a29 100644 --- a/GPOZaurr.psd1 +++ b/GPOZaurr.psd1 @@ -1,11 +1,11 @@ @{ - AliasesToExport = '' + AliasesToExport = 'Find-GPO' Author = 'Przemyslaw Klys' CompanyName = 'Evotec' CompatiblePSEditions = 'Desktop' Copyright = '(c) 2011 - 2020 Przemyslaw Klys @ Evotec. All rights reserved.' Description = 'Group Policy Eater is a PowerShell module that aims to gather information about Group Policies but also allows easy fixing for issues that you may expect finding in them.' - FunctionsToExport = 'Add-GPOPermission', 'Add-GPOZaurrPermission', 'Backup-GPOZaurr', 'Find-GPO', 'Get-GPOZaurr', 'Get-GPOZaurrAD', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrFiles', 'Get-GPOZaurrLegacyFiles', 'Get-GPOZaurrLink', 'Get-GPOZaurrLinkSummary', 'Get-GPOZaurrOwner', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermission', 'Get-GPOZaurrPermissionConsistency', 'Get-GPOZaurrSysvol', 'Get-WMIFilter', 'Get-GPOZaurrWMI', 'Invoke-GPOZaurrPermission', 'New-GPOZaurrWMI', 'Remove-GPOPermission', 'Remove-GPOZaurr', 'Remove-GPOZaurrLegacyFiles', 'Remove-GPOZaurrOrphanedSysvolFolders', 'Remove-GPOZaurrPermission', 'Remove-GPOZaurrWMI', 'Repair-GPOZaurrPermissionConsistency', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles', 'Select-GPOTranslation', 'Set-GPOOwner', 'Set-GPOZaurrOwner' + FunctionsToExport = 'Add-GPOPermission', 'Add-GPOZaurrPermission', 'Backup-GPOZaurr', 'Get-GPOZaurr', 'Get-GPOZaurrAD', 'Get-GPOZaurrBackupInformation', 'Get-GPOZaurrFiles', 'Get-GPOZaurrLegacyFiles', 'Get-GPOZaurrLink', 'Get-GPOZaurrLinkSummary', 'Get-GPOZaurrOwner', 'Get-GPOZaurrPassword', 'Get-GPOZaurrPermission', 'Get-GPOZaurrPermissionConsistency', 'Get-GPOZaurrSysvol', 'Get-WMIFilter', 'Get-GPOZaurrWMI', 'Invoke-GPOZaurr', 'Invoke-GPOZaurrPermission', 'New-GPOZaurrWMI', 'Remove-GPOPermission', 'Remove-GPOZaurr', 'Remove-GPOZaurrLegacyFiles', 'Remove-GPOZaurrOrphanedSysvolFolders', 'Remove-GPOZaurrPermission', 'Remove-GPOZaurrWMI', 'Repair-GPOZaurrPermissionConsistency', 'Restore-GPOZaurr', 'Save-GPOZaurrFiles', 'Select-GPOTranslation', 'Set-GPOOwner', 'Set-GPOZaurrOwner' GUID = 'f7d4c9e4-0298-4f51-ad77-e8e3febebbde' ModuleVersion = '0.0.46' PowerShellVersion = '5.1' diff --git a/Private/GpoTypes/SecurityOptions.ps1 b/Private/GpoTypes/SecurityOptions.ps1 new file mode 100644 index 0000000..59e7021 --- /dev/null +++ b/Private/GpoTypes/SecurityOptions.ps1 @@ -0,0 +1,77 @@ +$SecurityOptions = @{ + Category = 'SecuritySettings' + Settings = 'SecurityOptions' + # This is to make sure we're not loosing anything + # We will detect this and if something is missing provide details + PossibleProperties = @( + 'KeyName' + 'SettingNumber' + 'Display' + 'SystemAccessPolicyName' + 'SettingString' + ) + Translate = [ordered] @{ + 'KeyName' = 'KeyName' + 'KeyDisplayName' = 'Display', 'Name' + 'KeyDisplayUnits' = 'Display', 'Units' + 'KeyDisplayBoolean' = 'Display', 'DisplayBoolean' + 'KeyDisplayString' = 'Display', 'DisplayString' + 'SystemAccessPolicyName' = 'SystemAccessPolicyName' + 'SettingString' = 'SettingString' + 'SettingNumber' = 'SettingNumber' + } + Types = [ordered] @{ + 'KeyDisplayBoolean' = { try { [bool]::Parse($args) } catch { $null } } + } +} + +$LugsSettingsLocalUsersAndGroups = @{ + PossibleProperties = @( + 'clsid' + 'Group' + 'User' + ) + CustomCode = { + + } + <# + LoopOver = @{ + User = @{ + + } + Group = @{ + + } + } + #> + + + <# + Translate = [ordered] @{ + Name = #= $Entry.name + Changed = #= [DateTime] $Entry.changed + GPOSettingOrder = #= $Entry.GPOSettingOrder + Filters = #= $Entry.Filters + ActionType = #= $NestedType + Action = #= $Entry.Properties.Action + UserName = #= $Entry.Properties.userName + NewName = #= $Entry.Properties.newName + Description = #= $Entry.Properties.description + DeleteAllUsers = #= [bool] $Entry.Properties.deleteAllUsers + DeleteAllGroups = #= [bool] $Entry.Properties.deleteAllGroups + RemoveAccounts = #= [bool] $Entry.Properties.removeAccounts + GroupSid = #= $Entry.Properties.groupSid + GroupName = #= $Entry.Properties.groupName + MembersName = #= $Member.Name + MembersAction = #= $Member.Action + MembersSid = #= $Member.Sid + FullName = #= $Entry.Properties.fullName + AccountCpassword = #= $Entry.Properties.cpassword + AccountChangeLogon = #= [bool] $Entry.Properties.changeLogon + AccountNoChange = #= [bool] $Entry.Properties.noChange + AccountNeverExpires= #= [bool] $Entry.Properties.neverExpires + AccountDisabled = #= [bool] $Entry.Properties.acctDisabled + SubAuthority = #= $Entry.Properties.subAuthority + } + #> +} \ No newline at end of file diff --git a/Private/GpoTypes/SecuritySettingsSecurityOptions.ps1 b/Private/GpoTypes/SecuritySettingsSecurityOptions.ps1 deleted file mode 100644 index 2a5a996..0000000 --- a/Private/GpoTypes/SecuritySettingsSecurityOptions.ps1 +++ /dev/null @@ -1,24 +0,0 @@ -$SecuritySettingsSecurityOptions = @{ - # This is to make sure we're not loosing anything - # We will detect this and if something is missing provide details - PossibleProperties = @( - 'KeyName' - 'SettingNumber' - 'Display' - 'SystemAccessPolicyName' - 'SettingString' - ) - Translate = [ordered] @{ - 'KeyName' = 'KeyName' - 'KeyDisplayName' = 'Display', 'Name' - 'KeyDisplayUnits' = 'Display', 'Units' - 'KeyDisplayBoolean' = 'Display', 'DisplayBoolean' - 'KeyDisplayString' = 'Display', 'DisplayString' - 'SystemAccessPolicyName' = 'SystemAccessPolicyName' - 'SettingString' = 'SettingString' - 'SettingNumber' = 'SettingNumber' - } - Types = [ordered] @{ - 'KeyDisplayBoolean' = { try { [bool]::Parse($args) } catch { $null } } - } -} \ No newline at end of file diff --git a/Private/Invoke-GPOTranslation.ps1 b/Private/Invoke-GPOTranslation.ps1 index e407ea5..a3aed9b 100644 --- a/Private/Invoke-GPOTranslation.ps1 +++ b/Private/Invoke-GPOTranslation.ps1 @@ -2,6 +2,7 @@ [cmdletBinding()] param( [System.Collections.IDictionary] $InputData, + [string] $Report, [string] $Category, [string] $Settings ) @@ -15,7 +16,7 @@ $AllProperties = Select-Properties -AllProperties -Objects $InputData.$Category.$Settings $MissingProperties = $AllProperties | Where-Object { $_ -notin 'DisplayName', 'DomainName', 'GUID', 'Linked', 'LinksCount', 'Links', 'GPOType', 'GPOCategory', 'GPOSettings' } foreach ($Property in $MissingProperties) { - if ($Property -notin $Script:GPODitionary[$Category][$Settings]['PossibleProperties']) { + if ($Property -notin $Script:GPODitionary[$Report]['PossibleProperties']) { Write-Warning "Invoke-Translation - We're missing property for $Category / $Settings - $Property" } } @@ -33,9 +34,9 @@ } # Lets loop thru each Translate Property - foreach ($PropertyName in $Script:GPODitionary[$Category][$Settings]['Translate'].Keys) { + foreach ($PropertyName in $Script:GPODitionary[$Report]['Translate'].Keys) { # We get property that we expect on our $GPOEntry object - $Property = $Script:GPODitionary[$Category][$Settings]['Translate'][$PropertyName] + $Property = $Script:GPODitionary[$Report]['Translate'][$PropertyName] # Since it's possible we may be interested in something that is a nested property we need to do some looping into the object $Value = $GPOEntry @@ -44,9 +45,9 @@ } # Now we simply assing that value to new GPO Entry # But before we do so, we need to check if it has required type - if ($Script:GPODitionary[$Category][$Settings]['Types'][$PropertyName]) { + if ($Script:GPODitionary[$Report]['Types'][$PropertyName]) { # This basically checks in dictionary if we want to convert the type from a string to lets say boolean or something else - $CreateGPO["$PropertyName"] = Invoke-Command -Command $Script:GPODitionary[$Category][$Settings]['Types'][$PropertyName] -ArgumentList $Value + $CreateGPO["$PropertyName"] = Invoke-Command -Command $Script:GPODitionary[$Report]['Types'][$PropertyName] -ArgumentList $Value } else { $CreateGPO["$PropertyName"] = $Value } diff --git a/Private/Script.GPODictionary.ps1 b/Private/Script.GPODictionary.ps1 index 6727711..484a1fb 100644 --- a/Private/Script.GPODictionary.ps1 +++ b/Private/Script.GPODictionary.ps1 @@ -1,5 +1,6 @@ $Script:GPODitionary = @{ - SecuritySettings = @{ - SecurityOptions = $SecuritySettingsSecurityOptions - } + SecurityOptions = $SecurityOptions + #LugsSettings = @{ + # LocalUsersAndGroups = $LugsSettingsLocalUsersAndGroups + } \ No newline at end of file diff --git a/Public/Find-GPO.ps1 b/Public/Invoke-GPOZaurr.ps1 similarity index 84% rename from Public/Find-GPO.ps1 rename to Public/Invoke-GPOZaurr.ps1 index f03a4ee..acfa846 100644 --- a/Public/Find-GPO.ps1 +++ b/Public/Invoke-GPOZaurr.ps1 @@ -1,4 +1,5 @@ -function Find-GPO { +function Invoke-GPOZaurr { + [alias('Find-GPO')] [cmdletBinding(DefaultParameterSetName = 'Default')] param( [Parameter(ParameterSetName = 'Default')][alias('ForestName')][string] $Forest, @@ -10,18 +11,7 @@ [Parameter(ParameterSetName = 'Default')] [Parameter(ParameterSetName = 'Local')] - [ValidateSet('LocalUsersAndGroups', 'Autologon', 'RegistrySettings', 'RegistryPolicies', 'Scripts')][string[]] $Type = @( - 'LocalUsersAndGroups' - 'Autologon' - 'RegistrySettings' - 'RegistryPolicies' - 'Scripts' - 'SoftwareInstallation' - 'SecurityOptions' - 'Account' - 'SystemServices' - ), - + [string[]] $Type, [Parameter(ParameterSetName = 'Default')] [Parameter(ParameterSetName = 'Local')] [switch] $NoTranslation, @@ -29,8 +19,13 @@ [Parameter(ParameterSetName = 'Default')] [Parameter(ParameterSetName = 'Local')] [string] $Splitter = [System.Environment]::NewLine, - [switch] $FullObjects + [switch] $FullObjects, + + [ValidateSet('HTML', 'Object')][string] $OutputType = 'Object' ) + if ($Type.Count -eq 0) { + $Type = $Script:GPODitionary.Keys + } if ($GPOPath) { if (Test-Path -LiteralPath $GPOPath) { <# @@ -159,19 +154,27 @@ $Output } else { $TranslatedOutput = [ordered] @{} - foreach ($Category in $Script:GPODitionary.Keys) { - if (-not $TranslatedOutput[$Category]) { - $TranslatedOutput[$Category] = [ordered] @{} - } - foreach ($Setting in $Script:GPODitionary[$Category].Keys) { - if (-not $TranslatedOutput[$Category][$Setting]) { - $TranslatedOutput[$Category][$Setting] = [ordered] @{} - } - $TranslatedOutput[$Category][$Setting] = Invoke-GPOTranslation -InputData $Output -Category $Category -Settings $Setting - } + foreach ($Report in $Type) { + $Category = $Script:GPODitionary[$Report]['Category'] + $Settings = $Script:GPODitionary[$Report]['Settings'] + + #if (-not $TranslatedOutput[$Report]) { + # $TranslatedOutput[$Report] = [ordered] @{} + #} + #foreach ($Setting in $Settings) { + # if (-not $TranslatedOutput[$Category][$Settings]) { + # $TranslatedOutput[$Category][$Settings] = [ordered] @{} + # } + $TranslatedOutput[$Report] = Invoke-GPOTranslation -InputData $Output -Category $Category -Settings $Settings -Report $Report + #} } $TranslatedOutput } } -#Select-Properties -AllProperties -Objects ($Output.SecuritySettings.SecurityOptions | Where-Object { $_.Display -ne $null }) \ No newline at end of file +[scriptblock] $SourcesAutoCompleter = { + param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters) + + $Script:GPODitionary.Keys | Sort-Object | Where-Object { $_ -like "*$wordToComplete*" } +} +Register-ArgumentCompleter -CommandName Find-GPO -ParameterName Type -ScriptBlock $SourcesAutoCompleter \ No newline at end of file diff --git a/README.md b/README.md index 4d0cf31..0d2457c 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ That's it. Whenever there's a new version, you run the command, and you can enjo - 0.0.46 - Unreleased - Additional protection for `Get-GPOZaurrAD` for CNF duplicates - Update to `Save-GPOZaurrFiles` - - Added `Find-GPO` (heavy work in progress) + - Added `Invoke-GPOZaurr` (alias: `Find-GPO`) (heavy work in progress) - 0.0.45 - 26.06.2020 - During publishing ADEssentials required functions are now merged to prevent cyclic dependency bug [Using ModuleSpec syntax in RequiredModules causes incorrect "cyclic dependency" failures](https://github.com/PowerShell/PowerShell/issues/2607) - 0.0.44 - 24.06.2020