Using PowerShell with Microsoft Azure

Posted by Staff   |   Monday, October 13th, 2014

This is a guest post by Debra Shinder.

To the delight of some and the consternation of others, Microsoft has become more and more command line-centric over the past several years. This trend began in earnest with the initial release of PowerShell in 2006. True to its name, PowerShell provides a powerful interface for performing administrative tasks quickly and efficiently, both locally and remotely, using scripts and cmdlets.

During the same time period, Microsoft has begun to move with a vengeance “to the cloud,” now seemingly focusing most of its talent and attention more on the Azure platform than on its venerable Windows Server products. But those IT pros who have grown to love PowerShell need not fear; your PS expertise will still come in handy as you hone your skills for moving to a cloud-based environment. You’ll be happy to know you can install Azure PowerShell for managing your Azure environment.

There are some differences, though. Assuming you’re using Microsoft’s hosted Azure service, many of the cmdlets have to have information about your Azure subscription in order to work. That means you have to connect the computer you’re using to manage Azure to your subscription.

It’s easy enough to install the Azure PowerShell modules. The first step is to download and install Azure PowerShell and the Microsoft Web Platform Installer. The current version is 5.0. You can find detailed information on how to do that here.

SQL Express will be installed in the process.

Assuming you installed on Windows 8/8.1, you now have both the standard PowerShell console and the Azure PowerShell console. You can run the Azure cmdlets from either one. You can open either console by typing power in the Search, or on older operating systems such as Windows 7, you’ll find it in the All Programs menu.

Either way, the first step after installing and opening the console is to connect it to your Azure subscription. The easiest way to do that is to sign into Azure with your Microsoft account or company account. Azure Active Directory will then authenticate your credentials and generate an access token for Azure PowerShell to use to access the account.

To do this, in the Azure PowerShell console, type Add-AzureAccount. Then you’ll enter the email address and password for your Azure account. When Azure has authenticated the credentials, it will close the pop-up window.

Once your subscription is connected, you can start using the Azure cmdlets to perform common administrative tasks. A large number of cmdlets for various modules are available, including:

  • Azure Service Management cmdlets
  • Azure Automation cmdlets
  • Azure cmdlets for Microsoft Antimalware
  • Azure Active Directory cmdlets
  • Azure ExpressRoute cmdlets
  • Azure Managed Cache cmdlets
  • Azure Profile cmdlets
  • Azure Resource Manager cmdlets
  • Azure Rights Management cmdlets
  • Azure SQL Database cmdlets
  • Azure Traffic Manager cmdlets

You can find information on each of these on the MSDN web site here.

To find out what all the cmdlets in the Azure module are, type the command Get-Help Azure in the Azure PowerShell console.

When you install the Azure PowerShell package, it includes three modules: the Azure module, which include cmdlets that allow you to manage web sites, databases, virtual machines, storage accounts and media services. The cmdlets in this module are displayed in the screenshot above. Also included are the AzureResourceManager module and the AzureProfile module.

To use other modules, you will need to install them specifically. For example, if you want to manage Azure Active Directory with PowerShell, you’ll need to install the Azure AD module from the Microsoft Download Center. Different modules may have different prerequisites. For example, the Azure AD module requires that you have the Microsoft Online Services Sign-in Assistant version 7.0 or greater installed on your system. With the Azure AD module installed, you can connect to Azure Active Directory and manage users, group and role membership, service principals, domains, single sign-on and more.

Azure PowerShell is a great tool to have in your management arsenal. If you’re new to PowerShell, though, you’ll want to learn some of the basics before you tackle it. You can find out more about PowerShell in general from Brien Posey’s PowerShell Essentials article series over on the web site. Or check out Richard Hicks’ article Introduction to PowerShell with Windows Azure on