Thoughts, Dynamics 365, random business ideas, etc.

Create CSP Azure subscriptions using PowerShell in 4 easy steps

If you’re a Microsoft partner, and you want to create Azure subscriptions using PowerShell for CSP customers, here’s the post for you.

Prerequisites

  1. Need to be a CSP partner
  2. Need to have a customer account already setup
  3. Need to have an Azure Plan subscription created for your customer
  4. Need to have the permissions required to both login to Partner Center and to create new orders for your customers

Install the Partner Center PowerShell module

The Partner Center PowerShell module lets you do a lot of things; manage your Partner Center account, create new customers, and even create new licensing orders for customers. We’re using it for a far simpler reason today – to create Azure subscriptions using PowerShell.

First step is to use the Install-Module cmdlet to install and import the PartnerCenter module:

Install-Module PartnerCenter
Import-Module PartnerCenter

Authenticate to Partner Center

After you get the module installed, you’ll need to authenticate to Partner Center.

Connect-PartnerCenter

Since Partner Center requires its user use MFA, you’ll need to respond via an interactive login. Running the Connect-PartnerCenter command will open up a browser that requires you to login with your Partner Center credentials and will require you to approve an MFA request.

Once you do this, your PowerShell session is connected to Partner Center.

Get your customer ID and your billing account name

Where to find the customer ID

The customer ID that you’ll need from the next step is the tenant ID that you’re going to create the subscriptions for. You can find this in Partner Center–>Customers–>Customer list. The value in the “Microsoft ID” column is the customer ID.

Where to find the billing account name

There’s probably a better place to find this, but you can see the billing account name if you go to your Azure portal. Navigate to the “Cost Managmement + Billing” blade, click “Billing scopes” and find the record with a “Billing account type” of Microsoft Partner Agreement. Click that record and then click “Properties”. In the “Billing account ID” field, you’ll see the value. It looks weird – it’s two GUIDs concatenated with a colon in between them and then a date appended to the end – but you’ll want the whole thing.

Create the subscriptions using Power Shell

After you’ve done all the stuff above, you’re ready to execute the script. As you can see, after setting some variables, we’re basically looping through using a counter called $i and incrementing it. I’m also using that in my subscription name I’m creating to make it easier to find them in the Azure portal.

# Set the customer ID (replace with the actual customer tenant ID)
$customerId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

# Define the billing account name
$BillingAccountName = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx_xxxx-x-xx"

# Create 5 subscriptions
$subscriptions = @()
for ($i = 1; $i -le 5; $i++) {
    $subscriptionName = "Powershell subscription - $i"
    
    # Create the Azure subscription
    $subscription = New-PartnerAzureSubscription -BillingAccountName $BillingAccountName -CustomerId $customerId -DisplayName $subscriptionName
}

Inside the loop, we’re using the New-PartnerAzureSubscription cmdlet from the Partner Center module.

That’s it.

Wrap-up

The things that got me was finding the billing account name. I figured that out by manually creating a subscription and then running a different PowerShell query to return that subscription and all its properties (of which, the billing account name was one).

Also, it takes a while. Each subscription that needs to get created takes somewhere from 30 seconds to a minute. If you’re planning on creating a bunch of these, give yourself some time. If you need to restart it, just find the last subscription that was created, and change the $i = 1 to whatever the next number you want to start at is.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comments