PowerShell command prompt

Call Azure Cmdlets from System Center Orchestrator

Q: I'm trying to run Azure PowerShell cmdlets from System Center Orchestrator, but they aren't working; why not?

A: The built-in Run .NET Script activity uses native PowerShell to a 32-bit application. PowerShell 2.0 isn't compatible with the Azure cmdlet module; you need to use PowerShell 3.0 or later.

There are several ways to run a higher version of PowerShell from System Center Orchestrator. My preferred approach is to create a new session either on the local Orchestrator server or preferably some centralized PowerShell server where you'll install all the various modules you need to use. All PowerShell code is then executed on this session. For example, to create a session back to the local server, I would use the following code (assuming I have the Azure module installed locally):

$session = New-PSSession -ComputerName localhost
Invoke-Command -Session $session -ScriptBlock { 
    Import-Module Azure
    <Azure cmdlets and other code>  }

The fact that you're now essentially calling a script block can create complications in passing variables and getting more than one variable back. However, I cover this issue in the following FAQs:

In addition, I recommend that you wrap all the code in a try/catch structure so that any errors, even in the called code, are passed back, to help with troubleshooting. For example:

$ErrorActionPreference = "Stop"
try
{
    $session = New-PSSession -ComputerName localhost
    Invoke-Command -Session $session -ScriptBlock {

        Import-Module Azure
        Import-AzurePublishSettingsFile 'C:\Data\Microsoft Azure Subscription.publishsettings'
        Select-AzureSubscription -SubscriptionName 'Windows Azure Savill'

        <Your own code>

    } 
}
catch
{
    Throw $_.Exception
}
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish