-
-
Save f-bader/a95246a6b865d758834a1274a2b399ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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