Azure Scripting errors after upgrading Powershell to V4 – Select-AzureRmProfile / Save-AzureRmProfile

After upgrading Powershell to V4, few of my scripts started failing. Few updated commandlets are missing backward compatibility, Select-AzureRmProfile/ Save-AzureRmProfile are couple of the broken commandlets.

You can replace them with Import-AzureRmContext, and Save-AzureRmContext.

Code block I use for reference:

#
         $myprofile = "C:\tmp\" + [Environment]::UserName + "_Profile.json"
          $SubscriptionId = “asdfsadfsd”

#        Login-AzureRmAccount
        if(test-path $myprofile)
        {
            try
            {
                Import-AzureRmContext -Path $myprofile
                Select-AzureRmSubscription -SubscriptionId $SubscriptionId -ErrorAction Stop
            }
            catch
            {
                Login-AzureRmAccount
                Save-AzureRmContext -Path $myprofile -Force
            }
        }
        else
        {
            Login-AzureRmAccount
             Save-AzureRmContext -Path $myprofile -Force
        }
      Select-AzureRmSubscription -SubscriptionId $SubscriptionId -ErrorAction Stop
#

Ref:
Ref: Breaking changes: https://github.com/Azure/azure-powershell/blob/preview/documentation/release-notes/migration-guide.4.0.0.md

Additional Documentation: https://docs.microsoft.com/en-us/powershell/module/azurerm.profile/get-azurermcontext?view=azurermps-3.8.0

https://arcanecode.com/2017/04/19/what-happened-to-save-azurermprofile/#comment-128901

Still working on one more problem with Get-AzureRmSqlElasticPoolDatabase after Powershell upgrade to V4….

Error: Save-AzureRmContext : The term ‘Save-AzureRmContext’ is not recognized as the name of a cmdlet, function, script file,
or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and
try again.

Select-AzureRmProfile : The term ‘Select-AzureRmProfile’ is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.

Advertisements
This entry was posted in Azure, Powershell, SQL Server, Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s