Skip to content

Instantly share code, notes, and snippets.

@wsmelton
Created January 10, 2019 15:26
Show Gist options
  • Save wsmelton/4f9f07a3cb02506769a36d5aa6bf47e6 to your computer and use it in GitHub Desktop.
Save wsmelton/4f9f07a3cb02506769a36d5aa6bf47e6 to your computer and use it in GitHub Desktop.
Basic template for any runbook in Azure Automation to connect to subscription and access other resources
#region Az Connection
$RunAsCn = Get-AutomationConnection -Name "AzureRunAsConnection"
$cnParams = @{
"ServicePrincipal" =$true;
"TenantID" =$RunAsCn.TenantID;
"ApplicationId" =$RunAsCn.ApplicationID;
"CertificateThumbprint" =$RunAsCn.CertificateThumbprint;
}
$null = Connect-AzureRmAccount @cnParams
$null = Set-AzureRmContext -SubscriptionId $RunAsCn.SubscriptionID > $null
$endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment