-
-
Save f-bader/870ac600a6520dd7eca15903e35456aa to your computer and use it in GitHub Desktop.
Start a Runbook with an array
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
param( | |
[Parameter(Mandatory = $true)]$Parameter | |
) | |
$Parameter.GetType() | |
if ($Parameter -is [array]) { | |
Write-Output "It's an array. No conversion necessary." | |
} else { | |
try { | |
$Parameter = $Parameter | ConvertFrom-Json | |
Write-Output "Converted from JSON to array" | |
} catch { | |
$Parameter = @($Parameter) | |
Write-Output "Converted from String to array" | |
} | |
} | |
$Parameter.GetType() | |
$Parameter |
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 | |
$AzureAutomationRunbook = "Test-ObjectConversion" | |
$HybridWorker = "HybridWorkerGroup" | |
# Start runbook and parameter is an array | |
$AzureRunbookParameter = @{ | |
"Parameter" = "String" | |
} | |
Get-AzureRmAutomationAccount | Start-AzureRmAutomationRunbook -Parameters $AzureRunbookParameter -Name $AzureAutomationRunbook -RunOn $HybridWorker | |
# Start runbook and parameter is an array | |
$AzureRunbookParameter = @{ | |
"Parameter" = @("Blue","Jeans") | |
} | |
Get-AzureRmAutomationAccount | Start-AzureRmAutomationRunbook -Parameters $AzureRunbookParameter -Name $AzureAutomationRunbook -RunOn $HybridWorker | |
# Start runbook and parameter is an JSON | |
$AzureRunbookParameter = @{ | |
"Parameter" = ( @("Blue","Jeans") | ConvertTo-Json ) | |
} | |
Get-AzureRmAutomationAccount | Start-AzureRmAutomationRunbook -Parameters $AzureRunbookParameter -Name $AzureAutomationRunbook -RunOn $HybridWorker |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment