As I’ve worked with Microsoft Azure, PowerShell has been a tool that has made my life easier. When I just managed one subscription, PowerShell was easy because I was able to do a few quick Bing searches and find the type of PowerShell cmdlet’s I needed to accomplish my task. Once I added additional subscriptions to my account, my old ways didn’t work any longer so I had to figure out how to manage multiple Azure accounts via PowerShell. I want to share a few of my favorite PowerShell cmdlet’s so you can see how I can manage multiple Microsoft Azure subscriptions with PowerShell.
Next, you’ll need to run the Azure PowerShell.
Once you’ve started PowerShell, your screen should look something like this.
|Remember you can always use Help if you need assistance with a specific cmdlet.
Try Help Get-AzurePublishSettingsFile
Now let me show you the cmdlets that allow me to connect to a specific Azure account and then upload virtual machines from on-premises to Azure.
The Get-AzurePublishSettingsFile cmdlet opens your default browser, signs into your Microsoft Azure account, and automatically downloads a .publishsettings file that contains information and a certificate for your Windows Azure subscription. Go ahead and save the .publishsettings file, you will need it for the next cmdlet.
The next cmdlet we’re going to use is the Import-AzurePublishSettingsFile cmdlet, it will leverage the .publishsettings file we created with the Get-AzurePublishSettingsFile.
After you execute the Import-AzurePublishSettingsFile cmdlet, you’ve now connected your PowerShell session to your Microsoft Azure account(s).
The two steps above have always worked for me, but once I setup additional subscriptions, I could no longer just upload to a storage account. With multiple subscriptions, you need to select which subscription you are going to work with. The cmdlet Get-AzureSubscription will show all of the subscriptions I have access to, then the cmdlet Select-AzureSubscription allows me to select the appropriate Azure subscription.
I then use the Get-AzureStorageAccount cmdlet to enumerate the available storage accounts for that particular subscription.
Now I’ve identified my Azure Account and Storage Account that I want to upload my Virtual Machine to, now I just need to do the upload. I use the cmdlet Add-AzureVhd to do the actual upload, but I use variables to set everything up first.
The three lines above will start the upload of your local VHD to your Azure storage account.
Keep in mind that you can only upload VHD’s, not VHDx’s and the VHDs must be fixed size, not dynamically expanding. If you use the Add-AzureVhd cmdlet, it will actually convert your dynamically expanding VHD to fixed size so you don’t have to worry about that. If you are using VHDx’s, Hyper-V manager can convert your VHDx’s to a VHD’s.
In Summary, here are the cmdlet’s I talked about in the order I use them.
Until next time,