From e2bba32a57bdade8cfb0ec7cc9b50d65f428537f Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Sat, 15 Aug 2020 11:22:37 +0200 Subject: [PATCH] Update --- Public/Get-GPOZaurrWmi.ps1 | 15 ++++++++++++--- Public/Invoke-GPOZaurrSupport.ps1 | 11 +++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Public/Get-GPOZaurrWmi.ps1 b/Public/Get-GPOZaurrWmi.ps1 index 7b6c0db..c9ef3fa 100644 --- a/Public/Get-GPOZaurrWmi.ps1 +++ b/Public/Get-GPOZaurrWmi.ps1 @@ -6,10 +6,11 @@ [alias('ForestName')][string] $Forest, [string[]] $ExcludeDomains, [alias('Domain', 'Domains')][string[]] $IncludeDomains, - [System.Collections.IDictionary] $ExtendedForestInformation + [System.Collections.IDictionary] $ExtendedForestInformation, + [switch] $AsHashtable ) + $Dictionary = [ordered] @{} $wmiFilterAttr = 'msWMI-Name', 'msWMI-Parm1', 'msWMI-Parm2', 'msWMI-Author', 'msWMI-ID', 'CanonicalName', 'Created', 'Modified' - $ForestInformation = Get-WinADForestDetails -Forest $Forest -IncludeDomains $IncludeDomains -ExcludeDomains $ExcludeDomains -ExtendedForestInformation $ExtendedForestInformation foreach ($Domain in $ForestInformation.Domains) { $QueryServer = $ForestInformation['QueryServers'][$Domain]['HostName'][0] @@ -52,7 +53,7 @@ -join ($WMI[$i + 5], ';' , $WMI[$i + 6]) } } - [PSCustomObject] @{ + $WMIObject = [PSCustomObject] @{ DisplayName = $_.'msWMI-Name' Description = $_.'msWMI-Parm1' DomainName = $Domain @@ -68,9 +69,17 @@ CanonicalName = $_.CanonicalName DistinguishedName = $_.'DistinguishedName' } + if (-not $AsHashtable) { + $WMIObject + } else { + $Dictionary[$WMIObject.ID] = $WMIObject + } } } + if ($AsHashtable) { + $Dictionary + } } <# CanonicalName : ad.evotec.xyz/System/WMIPolicy/SOM/{E988C890-BDBC-4946-87B5-BF70F39F4686} diff --git a/Public/Invoke-GPOZaurrSupport.ps1 b/Public/Invoke-GPOZaurrSupport.ps1 index e93348f..3119287 100644 --- a/Public/Invoke-GPOZaurrSupport.ps1 +++ b/Public/Invoke-GPOZaurrSupport.ps1 @@ -52,13 +52,14 @@ } try { #Write-Verbose "Request-GPOZaurr - ComputerName: $($SplatPolicy['Computer']) UserName: $($SplatPolicy['User'])" - $ResultantSetPolicy = Get-GPResultantSetOfPolicy @SplatPolicy + $ResultantSetPolicy = Get-GPResultantSetOfPolicy @SplatPolicy -ErrorAction Stop } catch { if ($_.Exception.Message -eq 'Exception from HRESULT: 0x80041003') { Write-Warning "Request-GPOZaurr - Are you running as admin? $($_.Exception.Message)" return } else { - Write-Warning "Request-GPOZaurr - Error: $($_.Exception.Message)" + $ErrorMessage = $($_.Exception.Message).Replace([Environment]::NewLine, ' ') + Write-Warning "Request-GPOZaurr - Error: $ErrorMessage" return } } @@ -100,9 +101,11 @@ if ($PolicyContent.Rsop.UserResults) { $Output.UserResults = ConvertFrom-XMLRSOP -Content $PolicyContent.Rsop -ResultantSetPolicy $ResultantSetPolicy -ResultsType 'UserResults' -Splitter $Splitter } - if ($Type -eq 'Object') { + + New-GPOZaurrReportConsole -Results $Output + if ($Type -contains 'Object') { $Output - } elseif ($Type -eq 'HTML') { + } elseif ($Type -contains 'HTML') { New-GPOZaurrReportHTML -Path $Path -Offline:$Offline -Open:(-not $PreventShow) -Support $Output } }