Private/Get-ApplianceData.ps1

<#
.SYNOPSIS
    Gets individual Appliance configuration data from GREYHOUND Control Center (GCC)
.DESCRIPTION
    Long description
.EXAMPLE
    Example of how to use this cmdlet
#>

function Get-ApplianceData {
    [CmdletBinding(DefaultParameterSetName='Parameter Set 1',
                   SupportsShouldProcess=$true,
                   PositionalBinding=$false,
                   HelpUri = 'http://www.microsoft.com/',
                   ConfirmImpact='Medium')]
    [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, 
                   ParameterSetName='Parameter Set 2')]
        [string[]]$ApplianceSerialNumbers
    )
    
    $GccUri         = 'https://greyhound-software.com/gcc/xmlrpc/'
    $ContentType    = 'application/xml'
  
    for ($i=0; $i -lt $ApplianceSerials.Count; $i++) {$SerialValues = $SerialValues + "<value>" + $ApplianceSerials[$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
    {
        Write-Host 'Der GCC-Abruf war erfolgreich.'
    }

    $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).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 'Fehler beim GCC-Abruf aufgetreten:' $FaultString -ForegroundColor Red
    }

return $NewObject

}