How to Login without prompt?

后端 未结 4 2310
栀梦
栀梦 2020-12-13 06:27

I tried following commands to get a noprompt faster login experience but each time i find login popup. I even tried using the certificate initially but since that didn\'t pr

4条回答
  •  不知归路
    2020-12-13 07:01

    You can use -Credential parameter, and DPAPI to login.

    First, run the following PowerShell once to store a secured password for your account.

    Read-Host "Enter Password" -AsSecureString | ConvertTo-SecureString `
    -AsPlainText -Force | ConvertFrom-SecureString | Out-File "C:\Password.txt"
    

    And then, you can use the following script to login.

    # The azure account here must not be a Live ID.
    $username = ""
    $SecurePassword = Get-Content "C:\Password.txt" | ConvertTo-SecureString
    $cred = new-object -typename System.Management.Automation.PSCredential `
         -argumentlist $username, $SecurePassword
    
    Login-AzureRmAccount -Credential $cred
    

    An other way would be using Service Principal. First, you should follow the article to create a Service Principal

    And then, use the following script to login.

    $clientID = ""
    $key = ""
    $SecurePassword = $key | ConvertTo-SecureString -AsPlainText -Force
    $cred = new-object -typename System.Management.Automation.PSCredential `
         -argumentlist $clientID, $SecurePassword
    $tenantID = ""
    
    Add-AzureRmAccount -Credential $cred -TenantId $tenantID -ServicePrincipal
    

提交回复
热议问题