Forum Discussion

Patrick Rote's avatar
Patrick Rote
Iron Contributor
Jan 18, 2022

Connect to Azure AD from Powershell without prompt - what are my options?

Hi there,
I want to schedule some script in PowerShell and i would need to login into Azure AD first.
Is it possible to login to Azure AD without a prompt as the script needs to be automates/scheduled
Can I use app registration with client ID and Clients secret with powershell.
I also have a dedicated account which doesn't have MFA.

Any resources would be appreciated

Thanks

9 Replies

  • Alan2022's avatar
    Alan2022
    Iron Contributor

    Hi Patrick Rote 

     

    # Save User Credentials
    # New-StoredCredential -Target MyAccount -Username <Username> -Password <Password>
    
    # User Authentication
    $ua = Get-StoredCredential -Target MyAccount
    $credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $ua.UserName,$ua.Password
    
    # Login to your Azure Account
    Connect-AzAccount -Tenant '<TenantID>' -Credential $credential

     

    Still working until now.

     

     

     

    • ERobillard's avatar
      ERobillard
      Brass Contributor
      Hspinto is correct, and the luck of Alan2022 will become useless after June 23. If you stuck with Connect-AzAccount your prize is getting to get to write this twice. Here's an article on upgrading from the AD API to MSGraph: https://learn.microsoft.com/en-us/powershell/microsoftgraph/migration-steps?view=graph-powershell-1.0
  • Yes you can use SPN or certificates

    https://docs.microsoft.com/en-us/powershell/azure/authenticate-azureps?view=azps-7.1.0
      • Patrick Rote's avatar
        Patrick Rote
        Iron Contributor
        Thanks hspinto for your response.
        I have a dedicated acct that password doesn't expire and no MFA. Will this work?
        What is Managed Identity and how can i achieve this?
  • tringler's avatar
    tringler
    Copper Contributor
    You can just pass your username/password to Connect-AzAccount.
    • Patrick Rote's avatar
      Patrick Rote
      Iron Contributor
      Thanks Tringler . Can you please give me an example. I'm using Connect-AzureAD

Resources