Get-AppvZeroPortalCmdLetConfiguration
Returns the current ZeroPortal module configuration.
Beschreibung
Invoke-RestMethod gained -Form only in PowerShell 6; this module has to run
under Windows PowerShell 5.1, so the multipart body is built by hand with
HttpClient. The certificate bypass needs no extra handling: on .NET
Framework HttpClient goes through ServicePointManager, which
Set-AppvZeroPortalCmdLetConfiguration already configures.
#>
param(
[Parameter(Mandatory)] [string] $Uri,
[Parameter(Mandatory)] [string] $FilePath,
[hashtable] $Fields = $null
)
Add-Type -AssemblyName System.Net.Http -ErrorAction SilentlyContinue
$handler = New-Object System.Net.Http.HttpClientHandler
$handler.UseDefaultCredentials = $true
$client = New-Object System.Net.Http.HttpClient($handler)
$client.Timeout = [TimeSpan]::FromMinutes(10)
try {
$content = New-Object System.Net.Http.MultipartFormDataContent
$bytes = [System.IO.File]::ReadAllBytes($FilePath)
$file = New-Object System.Net.Http.ByteArrayContent(,$bytes)
$file.Headers.ContentType = [System.Net.Http.Headers.MediaTypeHeaderValue]::Parse('application/xml')
$content.Add($file, 'file', [System.IO.Path]::GetFileName($FilePath))
if ($Fields) {
foreach ($entry in $Fields.GetEnumerator()) {
foreach ($value in @($entry.Value)) {
$content.Add((New-Object System.Net.Http.StringContent([string]$value)), $entry.Key)
}
}
}
# GetAwaiter().GetResult() rather than .Result: it surfaces the real
# exception instead of wrapping it in an AggregateException.
$response = $client.PostAsync($Uri, $content).GetAwaiter().GetResult()
$text = $response.Content.ReadAsStringAsync().GetAwaiter().GetResult()
if (-not $response.IsSuccessStatusCode) {
$code = [int]$response.StatusCode
$hint = switch ($code) {
400 { "Bad request (400): $text" }
401 { 'Unauthorized (401) - check Kerberos/credentials.' }
403 { 'Access denied (403) - full administrators only.' }
default { "HTTP $code : $text" }
}
Write-Error $hint
return $null
}
if ([string]::IsNullOrWhiteSpace($text)) { return $null }
return $text | ConvertFrom-Json
}
finally {
if ($client) { $client.Dispose() }
}
}
function Resolve-ZeroPortalPackage { # Guid parameters are intentionally untyped: callers pass $null for parameters # that are not bound in the active parameter set (StrictMode-safe). param( [string]$ParameterSetName, [string]$Name, [string]$Version, $PackageID = $null, $VersionID = $null, $PackageGuid = $null, $VersionGuid = $null ) switch ($ParameterSetName) { { $_ -like 'ByName' } { $params = @{ Name = $Name } if ($Version) { $params['Version'] = $Version } $packages = Get-AppvZeroPortalPackage @params if (-not $packages) { Write-Error "No packages found matching name '$Name'$(if ($Version) { " version '$Version'" })." } return $packages } { $_ -like 'ByPackageID' } { $params = @{ PackageID = $PackageID } if ($VersionID -and $VersionID -ne [Guid]::Empty) { $params['VersionID'] = $VersionID } $packages = Get-AppvZeroPortalPackage @params if (-not $packages) { Write-Error "No packages found matching PackageID '$PackageID'." } return $packages } default { return [PSCustomObject]@{ PackageGuid = $PackageGuid; VersionGuid = $VersionGuid } } } }
function Resolve-ZeroPortalConnectionGroup { # GroupGuid is intentionally untyped: callers pass $null when it is not bound (StrictMode-safe). param( [string]$ParameterSetName, [string]$Name, $GroupGuid = $null ) switch ($ParameterSetName) { { $ -like 'ByName*' } { $all = Get-AppvZeroPortalConnectionGroup $matched = @($all | Where-Object { $.name -like $Name }) if (-not $matched -or $matched.Count -eq 0) { Write-Error "No connection groups found matching name '$Name'." return $null } return $matched } default { return [PSCustomObject]@{ groupGuid = $GroupGuid } } } }
endregion
region Configuration
<#
Beispiele
Get-AppvZeroPortalCmdLetConfiguration