Saving Azure Credentials
When using Powershell
2016-10-13
Rinse / Repeat When working with Azure Powershell you have to authenticate your cmdlet calls in order to actually get any work done.
This is pretty simple with Add-AzureRmAccount but having to do that for every script run gets tiresome fairly quick. To solve that you can save your credentials to a json file for a period of time with Save-AzureRmProfile and then you can load it with Select-AzureRmProfile
Automate the Automation
To wrap this I've been using this snippet:
$profileFileName = "AzureRmProfile.json"
$ProfileFilePath = (Join-Path $env:Temp $profileFileName)
# Sign In / Save Profile
if((Test-Path $profileFilePath) -eq $false) {
Write-Host "Logging in..." -ForegroundColor Yellow
Login-AzureRmAccount
Write-Host "Saving profile" -ForegroundColor Green
Save-AzureRmProfile -Path $profileFilePath
}
Select-AzureRmProfile -Path $profileFilePath | Out-Null