Managing SSH-Enabled Linux Hosts with Azure Automation

14 Temmuz, 2015 tarihinde gönderildi

Program Manager, System Center and Services

[UPDATE: this feature has been removed. If you'd like it brought back, let us know here that it's important to you. To set up SSH in Automation yourself, use this module, described in this presentation, to do so.]

Our team is frequently asked about Linux support by customers interested in unifying their workloads by using Azure Automation to manage not only Windows hosts, but Linux hosts as well. Today, we are pleased to announce our first steps into supporting this functionality. If you’ve used Azure Automation recently, you may have noticed a new module in your Automation Accounts – the Orchestrator.SshClient.Cmdlets module. This is our newest “global module”, meaning it has been rolled out by our team to all of our users. It currently contains a single cmdlet, Invoke-AutomationSshCommand, which you can use to – you guessed it! – invoke commands on any host with an accessible SSH port. A simple example of using this cmdlet follows, but you can use it to run any commands you may be accustomed to using on your Linux hosts. Also, it’s worth noting that the module and cmdlet currently implement a minimal amount of functionality that we think customers will find useful. As we continue to add functionality, let us know what other features are important to you by filling out this survey.


Our Invoke-AutomationSshCommand cmdlet functions much like the PowerShell core’s Invoke-Command cmdlet. It takes a ComputerName parameter to identify the host, a Credential parameter which takes a PowerShell credential object used to authenticate to that host, and a Command parameter, which takes a script block that will be executed on that host. Optionally, you may provide a Port parameter, if you are using a port number other than the standard 22 for SSH. Here’s an example of the cmdlet in action. This is a runbook which echoes some text on the Linux host and returns the result:

workflow Say-Hello
    #a linux host name
    $host = Get-AutomationVariable -Name linux-host-dns-name
    #admin credentials to the host
    $cred = Get-AutomationPSCredential -Name linux-host-admin
    $result = Invoke-AutomationSshCommand -ComputerName $host -Credential $cred -Command {
	    echo 'Hello there!';
    Write-Output $result

Invoke-AutomationSshCommand will block until the provided script block finishes running. When it does, anything written to the error stream on the host will also be written to the runbook’s error stream. Standard output will be returned as a string. So, the output of the above runbook will be “Hello there!”.


That’s it! Now you know how to use Azure Automation to run commands on Linux hosts over SSH. Once again, please fill out our survey if you care about this functionality and want to influence our future investments! For more cool ways to use Azure Automation, be sure to check out other posts under the Azure IT Pro/DevOps category. Happy Automating! Just getting started with Azure Automation? Learn about the service here, and follow Azure Automation on Twitter.