Subscriptions.psm1

<#
.SYNOPSIS
    This function converts a string of "SubscriptionOfferName:Quantity" comma-separated pairs to an array of PSCustomObjects
.DESCRIPTION
    This function converts a string of "SubscriptionOfferName:Quantity" comma-separated pairs to an array of PSCustomObjects
.PARAMETER subscriptions
    The string representing the subscription offer names and quantities
.EXAMPLE
    Convert-PartnerCenterSubscriptionString -Subscriptions $subscriptions
.EXAMPLE
    $subscriptions | Convert-PartnerCenterSubscriptionString
#>

function Convert-PartnerCenterSubscriptionString {
    param (
        [Parameter(Mandatory=$true, ValueFromPipeline=$true)]
        [String]$subscriptions
    )

    # Convert subscriptions into array
    $subscriptionArray = $subscriptions.Split(",")

    # Convert subscriptions into PSCustomObjects
    $subscriptionArray = $subscriptionArray | ForEach-Object {
        $fields = $_.Split(":")
        if ($fields.length -ne 2) {
            Write-Error "'$($_)' is not in the form of 'SubscriptionOfferName:Quantity'."
            return $null
        }
        [PSCustomObject]@{
            SubscriptionOfferType   = $fields[0]
            Quantity                = $fields[1]
        }
    }

    # Return the converted subscriptions
    return $subscriptionArray
}