diff --git a/Public/Invoke-GPOZaurrSupport.ps1 b/Public/Invoke-GPOZaurrSupport.ps1 new file mode 100644 index 0000000..a295e81 --- /dev/null +++ b/Public/Invoke-GPOZaurrSupport.ps1 @@ -0,0 +1,43 @@ +function Invoke-GPOZaurrSupport { + [cmdletBinding()] + param( + [ValidateSet('XML', 'Object')][string] $Type = 'Object', + [string] $ComputerName, + [string] $Path + ) + + $SplatPolicy = @{ + ReportType = 'xml' + Path = [io.path]::GetTempFileName().Replace('.tmp', ".xml") + } + if ($PSBoundParameters.ContainsKey('ComputerName')) { + $SplatPolicy['Computer'] = $ComputerName + } + if ($PSBoundParameters.ContainsKey('UserName')) { + $SplatPolicy['User'] = 'przemyslaw.klys' + } + try { + $ResultantSetPolicy = Get-GPResultantSetOfPolicy @SplatPolicy + } catch { + if ($_.Exception.Message -eq 'Exception from HRESULT: 0x80041003') { + Write-Warning "Request-GPOZaurr - Are you running as admin? $($_.Exception.Message)" + } else { + Write-Warning "Request-GPOZaurr - Error: $($_.Exception.Message)" + } + } + if (-not $ComputerName) { + # ComputerName is not set, lets use local + $ComputerName = $Env:COMPUTERNAME + } + # Loads created XML by resultant Output + [xml] $PolicyContent = Get-Content -LiteralPath $SplatPolicy.Path + if ($PolicyContent -and (Test-Path -LiteralPath $SplatPolicy.Path)) { + # lets remove temporary XML file + Remove-Item -LiteralPath $SplatPolicy.Path + } + if ($Type -eq 'XML') { + $PolicyContent.Rsop + } else { + ConvertFrom-XMLRSOP -Content $PolicyContent.Rsop -ComputerName $ComputerName -ResultantSetPolicy $ResultantSetPolicy + } +} \ No newline at end of file