Call Azure Cmdlets from System Center Orchestrator
Use Azure PowerShell from System Center Orchestrator.
September 30, 2014
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 localhostInvoke-Command -Session $session -ScriptBlock { Import-Module Azure }
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:
"Using Variables in Remote PowerShell Sessions" (passing arguments to a script block)
"Return Multiple Values from Sub-PowerShell Process" (return more than one value from a script block)
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:DataMicrosoft Azure Subscription.publishsettings' Select-AzureSubscription -SubscriptionName 'Windows Azure Savill' } }catch{ Throw $_.Exception}
About the Author
You May Also Like