Skip to content

Instantly share code, notes, and snippets.

Last active September 14, 2020 11:19
What would you like to do?
Write-Output "Hello from Runbook"
$apimSubscriptionId = "YOUR_SUBSCRIPTION_ID"
$apimServiceName = "YOUR_APIM_SERVICE_NAME"
# Copy/paste from default runbook
function setupConnection {
Write-Output "Start process getting AzureRunAsConnection"
$connectionName = "AzureRunAsConnection"
# Get the connection "AzureRunAsConnection "
$servicePrincipalConnection = Get-AutomationConnection -Name $connectionName
Write-Output $servicePrincipalConnection
"Logging in to Azure..."
Add-AzAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
catch {
if (!$servicePrincipalConnection)
$ErrorMessage = "Connection $connectionName not found."
throw $ErrorMessage
} else{
Write-Error -Message $_.Exception
throw $_.Exception
# Connecting to your Azure account
# Setting the context for apim
Set-AzContext -Subscription $apimSubscriptionId
$context = New-AzApiManagementContext -ResourceGroupName $rg -ServiceName $apimServiceName
# Random value
$value = [System.TimeZoneInfo]::ConvertTimeToUtc((get-date), (Get-TimeZone))
Set-AzApiManagementNamedValue -Context $context -NamedValueId "test" -Value $value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment