Facebook
From Jakub Kocur, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 49
  1. workflow HelloWorld
  2. {
  3.      $connectionName = "AzureRunAsConnection"
  4. try
  5. {
  6.     # Get the connection "AzureRunAsConnection "
  7.     $servicePrincipalConnection = Get-AutomationConnection -Name $connectionName      
  8.     "Logging in to Azure..."
  9.     $account = Add-AzureRmAccount `
  10.         -ServicePrincipal `
  11.         -TenantId $servicePrincipalConnection.TenantId `
  12.         -ApplicationId $servicePrincipalConnection.ApplicationId `
  13.         -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
  14. }
  15. catch {
  16.     if (!$servicePrincipalConnection)
  17.     {
  18.         $ErrorMessage = "Connection $connectionName not found."
  19.         throw $ErrorMessage
  20.     } else{
  21.         Write-Error -Message $_.Exception
  22.         throw $_.Exception
  23.     }
  24. }
  25. Write-Output $account
  26.    
  27.  
  28.  
  29.  
  30.  
  31.    Get-AzureRmVM -ResourceGroupName "TOTC"
  32. }