Private/Get-ApplianceXMLData.ps1
function Get-ApplianceDataXml { <# .SYNOPSIS Gets individual Appliance configuration data from GREYHOUND Control Center (GCC) .DESCRIPTION Long description .EXAMPLE Example of how to use this cmdlet #> [CmdletBinding(DefaultParameterSetName='Parameter Set 1', SupportsShouldProcess=$true, PositionalBinding=$false, HelpUri = '', ConfirmImpact='')] [Alias()] Param ( # Param1 help description [Parameter(Mandatory=$false, Position=0, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ValueFromRemainingArguments=$false, ParameterSetName='Parameter Set 1')] [AllowEmptyString()] [string]$ApplianceKey, # Param2 help description [Parameter(Mandatory=$true, Position=1, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, ValueFromRemainingArguments=$false)] [string[]]$ApplianceSerialNumbers ) $GccUri = 'https://greyhound-software.com/gcc/xmlrpc/' $ContentType = 'application/xml' for ($i=0; $i -lt $ApplianceSerialNumbers.Count; $i++) {$SerialValues = $SerialValues + "<value>" + $ApplianceSerialNumbers[$i] + "</value> "} $Body = "<?xml version=`"1.0`" encoding=`"UTF-8`"?> <methodCall> <methodName>GetApplianceData</methodName> <params> <param> <value> <array> <data> " + $SerialValues + " </data> </array> </value> </param> <param> <value> <string>" + $ApplianceKey + "</string> </value> </param> </params> </methodCall>" #Write-Host "`$Body = '$Body'" -ForegroundColor Yellow $GccResult = Invoke-RestMethod -Uri $GccUri -Method Post -Body $Body -ContentType $ContentType try { $FaultString = $GccResult.methodResponse.fault.value.struct.member[1].value.string } catch {} $GccValues = $GccResult.methodResponse.params.param.value.struct.member if (!$FaultString) { $NewObject = New-Object -TypeName psobject # Alle Daten außer ProductKeys speichern $GccValues | Where-Object Name -ne ProductKeys | ForEach-Object -Process {Add-Member -InputObject $NewObject -MemberType NoteProperty -Name $_.Name -Value $_.Value.InnerText -Force} # ProductKeys aus Array ermitteln und speichern $ProductKeyValues = ($GccValues | Where-Object Name -eq ProductKeys).value.array.data.value.struct.member Write-Host $ProductKeyValues if ($ProductKeyValues) { for ($i=0; $i -le ($ProductKeyValues | Measure-Command).Count - 1; $i++) { if ($ProductKeyValues.name[$i] -eq 'Name' -and $ProductKeyValues.name[$i+1] -eq 'ProductKey') { $NewObject | Add-Member -NotePropertyName $ProductKeyValues.value[$i].string -NotePropertyValue $ProductKeyValues.value[$i+1].string } } } else { Write-Host 'Es wurden keine Productkeys gefunden.' } } else { Write-Host 'GCC-Antwort:' $FaultString -ForegroundColor Red } return $NewObject } |