Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

auto login Azure powershell

Every time I open a azure powershell windows is it possible to auto login ?

i.e. this command given below should run everytime I open Azure Command window.

Get-AzurePublishSettingsFile (path in local machine)

or even Add-AzureAccount

like image 418
Blue Clouds Avatar asked Dec 05 '22 06:12

Blue Clouds


1 Answers

You can actually do it. Follow this process:

Open the Azure PowerShell initialization file at "C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1" for 64-bit OS or "C:\Program Files\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1" for 32-bit OS.

Add the following code just after the statement $VerbosePreference="Continue"

$username = "<username>"
$password = "<password>"
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($userName, $secpasswd)
Add-AzureAccount -Credential $cred

That should do the auto login for you

@Update: For Azure ARM mode, the command would be Login-AzureRMAccount -Credential $cred. This might not work with Microsoft accounts though.

like image 68
smonani Avatar answered Dec 29 '22 09:12

smonani