Search code examples
azureazure-powershellazure-automation

Azure automation account - how to use custom service principal for login instead of run as account?


In Azure automation account - how to use already existing service principal for login in powershell runbook instead of run as account ?

we dont get privilege to create service principal at our organisation .. so would like to use already existing service principal.


Solution

  • Just use the command below.

    $azureAplicationId ="<client-id>"
    $azureTenantId= "<tenant-id>"
    $azurePassword = ConvertTo-SecureString "<client-secret>" -AsPlainText -Force
    $psCred = New-Object System.Management.Automation.PSCredential($azureAplicationId , $azurePassword)
    Connect-AzAccount -Credential $psCred -TenantId $azureTenantId -ServicePrincipal
    

    enter image description here