Skip to content

Instantly share code, notes, and snippets.

@f-bader
Last active February 8, 2018 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f-bader/a95246a6b865d758834a1274a2b399ac to your computer and use it in GitHub Desktop.
Save f-bader/a95246a6b865d758834a1274a2b399ac to your computer and use it in GitHub Desktop.
#region Connect to Azure with certificate
try {
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"
Write-Output "Logging in to Azure..."
Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | Out-Null
# Switch Azure subscription
Write-Output "Switch to Azure SubscriptionId $($servicePrincipalConnection.SubscriptionId)"
Select-AzureRmSubscription -SubscriptionId $servicePrincipalConnection.SubscriptionId | Out-Null
} catch {
if (!$servicePrincipalConnection) {
throw "Connection $connectionName not found."
} else {
throw $_.Exception
}
}
#endregion
#region Start new runbook
$AzureAutomationRunbook = "SuperFunRunbook"
$HybridWorker = "HybridWorkerGroup"
# Set parameters
$AzureRunbookParameter = @{
"ParameterString" = "Blue Jeans"
"ParameterArray" = @("BLUE","BLACK")
}
# Start runbook
Get-AzureRmAutomationAccount | Start-AzureRmAutomationRunbook -Parameters $AzureRunbookParameter -Name $AzureAutomationRunbook -RunOn $HybridWorker
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment