I’ve been working a lot in the Azure PowerShell area of late. One thing I wanted to be able to do is have my scripts login automatically to Azure. In many examples the cmdlet Save-AzureRmProfile was used to save your Azure credentials, then later you could use Import-AzureRmProfile to import them.
But, when I attempted to run Save-AzureRmProfile I got the error ‘Save-AzureRmProfile is not recognized as the name of a cmdlet, function, script file, or operable program’. Huh? I checked the docs, and it does include a listing for Save-AzureRmProfile.
This is a case of the PowerShell AzureRM module getting ahead of the docs. After beating my head against the wall, I found the cmdlets had been replaced with the new noun of AzureRmContext.
To use them, first login to Azure manually. Then, use the new Save-AzureRmContext to save your information to a file.
# Setup – First login manually per previous section
Add-AzureRmAccount
# Now save your context locally (Force will overwrite if there)
$path = "C:\Azure\PS\ProfileContext.ctx’
Save-AzureRmContext -Path $path -Force
Once that’s done, from then on you can use the Import-AzureRmContext to automate the login.
# Once the above two steps are done, you can simply import
$path = ‘C:\Azure\PS\ProfileContext.ctx’
Import-AzureRmContext -Path $path
Be warned, this does present a security issue. If someone were to steal your context file, they could then login as you. You need to be sure your context file is stored in a safe location no one can get to.
For AzureRM 4.0, there is a migration guide explaining the change here:https://github.com/Azure/azure-powershell/blob/preview/documentation/release-notes/migration-guide.4.0.0.md
In 3.8, this was a *bug*, which is being tracked here:https://github.com/Azure/azure-powershell/issues/3822 We should have a 3.X release that fixes this issue in a few days.
Really useful update, thanks.
In order to automatically query resource groups or make changes, I found that I need to specify the subscription ID separately with the command below.
Set-AzureRmContext -SubscriptionId
Thank you! You saved my time 🙂
Thank you, thank you! I have some scripts I run only occasionally with the authentication ‘built in’, first with classic publishing profile xml and then after a day’s lost time the json publish profile formerly part of rm but now only a half day’s lost time you have helped me out. Kind of like trying to hit a moving target with a blind-fold on — as you say the Save-AzureRMProfile is blithely documented like it is still around. Much appreciated.