Subscriptions.psm1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<#
.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
}