メイン コンテンツにスキップ

 Subscribe

Introduction

By now you’ve probably had a chance to experiment with all the great features of Azure Automation through the Azure Portal – authoring runbooks and creating assets, starting jobs manually and on schedules, importing integration modules and viewing job output. Now what if I told you, you could do all these things and more easily and programmatically from the command line? Whether you want to use Azure Automation completely headless, or you’re just looking to script a few key actions like bulk runbook import, the Azure Automation cmdlets are for you.

Getting Started With the Azure Automation Cmdlets

Azure provides a PowerShell module that can be installed using the Microsoft Web Platform Installer, to manage all of your Azure services, including Azure Automation.

Azure Automation Capabilities in Depth: The Azure Automation PowerShell Cmdlets

 

The Azure PowerShell module currently provides 20 Azure Automation cmdlets that allow scripting of many of the actions you can perform from the Azure Automation portal. And that’s just the beginning. By Azure Automation’s general availability, we expect to have around 40 cmdlets to allow complete control of Azure Automation via PowerShell. And because these cmdlets are part of the Azure PowerShell module and we ship the Azure PowerShell module for use in Azure Automation, you can use these cmdlets with no additional effort within your runbooks, the first time you use Azure Automation.

To check out all the great cmdlet functionality the Azure PowerShell module provides, open up the PowerShell console on a host with the Azure module installed and type:

PS C:> Get-Command -Module Azure -Name *Automation*

This will return data on all Azure Automation cmdlets:

Azure Automation Capabilities in Depth: The Azure Automation PowerShell Cmdlets

 

To get details on how to use a specific Automation cmdlet, type:

PS C:> Get-Help Some-Command

But replace “Some-Command” with the Azure Automation cmdlet you’d like more information about. You can optionally add “–Detailed” or “–Full” to get larger sets of information about the cmdlet:

Azure Automation Capabilities in Depth: The Azure Automation PowerShell Cmdlets

 

You can also look at the Azure Automation Cmdlet Reference if you’d rather learn about the cmdlets in a web browser than in a PowerShell console.

How the Azure Automation Cmdlets Work

Just like the other Azure cmdlets, you must first set up a connection to an Azure subscription, for the Azure cmdlets to execute against. You can authenticate to Azure using a management certificate installed in the local certificate store, or via your Azure credentials. You’ll end up setting up your connection to Azure using some combination of Set-AzureSubscription, Import-AzurePublishedSettingsFile, Add-AzureAccount, and Select-AzureSubscription. You can find more information on how to connect to Azure from the Azure PowerShell cmdlets here. Once you set up the connection to Azure, you can use the Azure cmdlets without having to specify any credentials, endpoints, etc. It is all carried forward from your initial connection set up. However, you will need to provide the name of the Azure Automation account you want to access with each operation, via the AutomationAccountName parameter.

Running the Cmdlets

Here’s an example of running an Azure Automation cmdlet, and the type of output the cmdlets provide:

Azure Automation Capabilities in Depth: The Azure Automation PowerShell Cmdlets

 

One thing you’ll notice using the cmdlets is that, if you are continually acting upon the same Automation account, it can be cumbersome to continually pass the AutomationAccountName parameter into each cmdlet. Luckily, there is an easy way to pass this parameters into each Azure Automation cmdlet without having to write it out every time – splatting. Splatting allows you to define a set of parameters as a hashtable, and pass that set of parameters to any cmdlet. From the below, you can see this makes it super easy to add an Automation account name parameter and value to your Azure Automation cmdlets:

Azure Automation Capabilities in Depth: The Azure Automation PowerShell Cmdlets

Using the Azure Automation Cmdlets in Azure Automation

Another interesting tidbit about the Azure PowerShell module is that it is included as an out of box integration module in Azure Automation, which means you can use Automation cmdlets directly in your runbooks with no extra work. For example, here’s an Azure Automation runbook that starts another Azure Automation runbook asynchronously as a new job, and prints out info on that job:

Azure Automation Capabilities in Depth: The Azure Automation PowerShell Cmdlets

 

To learn more about starting runbooks from runbooks, see Chris Sanders’ blog post here. For another cool example of an Azure Automation runbook that depends on using the Azure Automation cmdlets, check out Gary Keong’s blog post on integrating Visual Studio Online with Azure Automation to enable runbook source control.

Summary

Hopefully by now you have a better understanding of all the wonderful things you can accomplish using the Azure Automation PowerShell cmdlets, and how the cmdlets themselves function. Not only can you use Azure Automation to automate your cloud and business processes, you can even automate Automation itself using these cmdlets! The Azure Automation team is super excited to see the kinds of runbooks and scripts you write to take advantage of the functionality Azure Automation and the Azure PowerShell module provide.

Just getting started with Azure Automation?  Learn about the service here, and follow Azure Automation on Twitter.

Want to get in contact with me, personally? Reach out via my blog or follow me on Twitter.

  • Explore

     

    Let us know what you think of Azure and what you would like to see in the future.

     

    Provide feedback

  • Build your cloud computing and Azure skills with free courses by Microsoft Learn.

     

    Explore Azure learning


Join the conversation