Error Run Login-AzureRmAccount to login

Hi,

I am running an Azure PowerShell Script as step which calls a Script module within the project which update app settings in webapp.

Script Modulde script:-

function UpdateSettings($hash, $slot) {
    if([String]::IsNullOrEmpty($slot)) {
        Write-host $slot "empty"
        Set-AzureRmwebApp -ResourceGroupName $resourceGroup -Name $webAppName -AppSettings $hash
    }
    else {
        Write-host $slot
        Set-AzureRmwebAppSlot -ResourceGroupName $resourceGroup -Name $webAppName -AppSettings $hash -Slot $slot
    }
}


Function SetAppSettings($WebappName, $ResouceGroup, $SubscriptionId, $slot)
{
#
#Get-InstalledModule
Write-host "passed in function AppName= $WebappName  ResourceGroup= $ResouceGroupName  subId=$SubscriptionId Slot=$slot"

#select subscription
Get-AzureRmSubscription -SubscriptionId $SubscriptionId | Select-AzureRmSubscription


# Load webapp settings
Write-Host "load webApplication and settings from Azure webApp $WebappName..."
Write-Host "Get-AzureRmwebApp -ResourceGroupName $ResouceGroup -Name $WebappName"
$webApp = Get-AzureRmwebApp -ResourceGroupName $ResouceGroup -Name $WebappName
$webAppSettings = $webApp.SiteConfig.AppSettings

# copy  app settings to hash table
foreach ($setting in $webAppSettings) {
        $hash[$setting.Name] = $setting.Value
    } 

Write-Host "Hash table with current appsetting Values"
$hash
       
$keys = @()
[array] $keys = $hash.keys

# loop through all the Octopus Parameters
$OctopusParameters.GetEnumerator() | % { 
    
    $found = $false
    $OctopusVariableName = $($_.key)
    $OctopusVariableValue = $($_.value)
    
    # there are 100s of in-built Octopus variables - ignore the internal ones that all
    # start with the word Octopus
    if (!$OctopusVariableName.StartsWith("Octopus"))
    {
        Write-host "Checking Octopus Variable: " $($_.key)
        
        # check to see if the Octopus key is in the set of variables from Azure
        foreach ($settingkey in $keys)
        {
            # if we do have a match, then change the value and set the found flag
            if ($($_.key) -eq "$settingkey") 
           {
               Write-host "Found a match for key: " $($_.key)
               $hash.Set_Item("$settingkey", $($_.value))
               $found = $true
           }
        }
        
        # if the octopus variable hasn't been found as part of the Azure variables
        if ($found -eq $false)
        {
            Write-host "Didn't find a match so adding it for key: " $OctopusVariableName
            # then we simply add it
            $hash.Add($($_.key), $($_.value))
        }
        
        Write-host "Finished Checking Octopus Variable: " $($_.key)
    }
        
}

Write-Host "Hash table with updated values"
$hash
UpdateSettings($hash)
} 

But getting the following error
Get-AzureRmSubscription : Run Login-AzureRmAccount to login.

I am not sure what to do next .? I assume, when I select the account, it should automatically authenticate it.
I have attached RAW log from the output.

ServerTasks-2341.log.txt (3 KB)

Step_screanshot.jpg

Hi,

Thanks for reaching out!

To be able to run Resource Management cmdlets such as Get-AzureRMWebApp & Set-AzureRMWebAppSlot you need to use a Service Principal Account in your Azure Powershell Script. In this case you are using a Management Certificate Account and that’s why you are getting this error and the blue message you can see on step_screanshot.jpg

Best regards,
Dalmiro