- Install Ansible on Windows - Thu, Jul 20 2023
- Use Azure Bastion as a jump host for RDP and SSH - Tue, Apr 18 2023
- Azure Virtual Desktop: Getting started - Fri, Apr 14 2023
Note that before you can follow the examples in this guide, you have to install Azure PowerShell 1.0.
Service Management vs. Resource Manager
In my time with Microsoft Azure thus far, I’ve used the Azure Management Portal (manage.windowsazure.com) and the Azure PowerShell module. These technologies rely upon the Azure Service Management application programming interfaces (APIs). Service Management has worked great for me—no complaints.
The “classic” Azure Management Portal.
Viewing the commands contained in the Azure Service Management module.
What’s confusing and frustrating is that now Microsoft steers us toward their new-ish Resource Manager service deployment system. The new Azure Portal (portal.microsoft.com) uses Resource Manager by default:
The new Azure Portal.
What’s crazy is how many Resource Manager PowerShell modules there are. Check out the following screenshot:
The new Azure Resource Manager APIs make PowerShell a bit more cumbersome to use.
Azure command discovery
All the standard rules apply when investigating Azure PowerShell commands. Run the following statement to list all commands in the Service Management module:
Get-Command –Module Azure | Select-Object –Property Name | Format-Wide –Column 2
As of this writing, I see 754 commands in the Service Management module. Wow! Now let’s view the available commands in the AzureRM* modules:
Get-Command –Module AzureRM* | Select-Object –Property Name | Format-Wide –Column 2
Piping Get-Command into Measure-Object tells me we have 787 total commands across all the Resource Manager modules.
By the way, installing Azure PowerShell v1.x via the WebPI gives you a customized PowerShell console named, appropriately enough, Microsoft Azure PowerShell. If you examine the properties for its shortcut icon, you see the following target:
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoExit -ExecutionPolicy Bypass -File "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1
If you really want to get geeky, open the ShortcutStartup.ps1 initialization script. All it does is pre-load the Azure PowerShell modules into the runspace and give a brief welcome message. Take a look here:
The Microsoft Azure PowerShell custom console is handy.
I hear quite a bit of grousing among Windows PowerShell MVPs who complain that the Resource Manager APIs and PowerShell modules are incompletely (or simply not) documented, and that many features are missing or half-baked. For that reason, we’ll focus on the “legacy” Service Management commands from here on.
My favorite way to access command help is to add the –ShowWindow switch parameter to the Get-Help cmdlet. Doing so puts the full help file (assuming you’ve run Update-Help to populate your local help repository) in a separate window, making it easier to keep your PowerShell console and the help screen separate.
Let’s say we want to learn how to create a VM using the Azure Service Management PowerShell module. First, we’ll find the appropriate command:
Get-Command -Noun AzureVM | Select-Object -Property Name Name ---------------- Export-AzureVM Get-AzureVM Import-AzureVM New-AzureVM Remove-AzureVM Restart-AzureVM Start-AzureVM Stop-AzureVM Update-AzureVM
Okay. It looks like we need New-AzureVM. Here’s how the command works:
Get-Help New-AzureVM -ShowWindow
The Microsoft Azure command documentation is … sparse.
Ouch! Look at the previous figure again. The documentation for Azure PowerShell (both the Service Management and Resource Manager varieties) is woefully lacking.
Connecting to your Azure subscription
So we’ve installed the Azure PowerShell module(s) and experimented with command discovery and online help. However, we can’t do anything in the Azure public cloud unless and until we connect our local PowerShell session with our Azure subscription. Let’s take care of that quickly.
Boy, it’s so much easier to get connected with the 1.x Azure PowerShell release. No more downloading and ingesting management certificates! First, we run Add-AzureAccount and provide our Azure email address and account password. Then we can use Get-AzureSubscription to see the associated Azure subscription(s).
It’s never been easier to connect PowerShell to your Azure subscription.
I have more than one Azure subscription, so I need to run the following command to set my default one:
Set-AzureSubscription –SubscriptionName ‘MyPreferredAzureSubscription’
Deploying a new Azure asset
Let’s finish up by using Azure Service Management to deploy a quick website. Doing so is delightfully easy:
New-AzureWebsite –Name ‘TimAzureWSTest’ –Location ‘West US’
We need the hostname, of course, so we’ll invoke Get-AzureWebsite:
Get-AzureWebsite Name : TimAzureWSTest State : Running Host Names : {timazurewstest.azurewebsites.net}
And if we point our Web browser to that hostname, we see the default home page:
A single line of PowerShell published this website to the Azure cloud.
As the following screenshot shows, we can manage our new Azure website through the Portal Web interface as well. I highlighted the FTP/FTPS hostnames because the first thing that most website admins want to do is get in there and manipulate the site’s content files.
Our PowerShell-created Azure website as seen from the Portal experience.