Skip to content

Instantly share code, notes, and snippets.

@svenmalvik
Last active September 14, 2020 11:19
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 svenmalvik/a3fec9487aa82948d46f45f87ae805dc to your computer and use it in GitHub Desktop.
Save svenmalvik/a3fec9487aa82948d46f45f87ae805dc to your computer and use it in GitHub Desktop.
Write-Output "Hello from Runbook"
$apimSubscriptionId = "YOUR_SUBSCRIPTION_ID"
$apimServiceName = "YOUR_APIM_SERVICE_NAME"
$rg = "YOUR_RESOURCE_GROUP"
# Copy/paste from default runbook
function setupConnection {
Write-Output "Start process getting AzureRunAsConnection"
$connectionName = "AzureRunAsConnection"
try
{
# 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
setupConnection
# 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