Skip to content

Credentials Expired? #7956

@ronbok

Description

@ronbok

Description

Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials.

Despite this being Az, not AzureRM, we get an error that tells you to use Connect-AzureRmAccount?

Also, this code worked fine on Windows, Windows PowerShell, using AzureRm. When reloading the saved file, it's not logging you back in

Script/Steps for Reproduction

#region Login-Az()

Function Login-Az()
{
Param ([String]$Subscription, [String]$UPN)

$ProfilePath = (Split-Path $Profile.CurrentUserCurrentHost) + "/"

$AzContext = Import-AzContext -Path $($ProfilePath + $UPN + "@$Subscription.json") -ErrorAction SilentlyContinue

If ([string]::IsNullOrEmpty($AzContext))

{

    $AzContext = Connect-AzAccount -Subscription $Subscription -Environment "AzureCloud"
    Save-AzContext -Profile $AzContext -Path $($ProfilePath + $AzContext.Context.Account.Id + "@$Subscription.json") -Force
    # Get-AzureRmContext

}
Else
{
    Select-AzSubscription -Name $AzContext.Context.Subscription.Name -Context $AzContext.Context
    
}

Return $AzContext

}
#endregion Login-Az()

Module Version

Get-Module -ListAvailable

Environment Data

$PSVersionTable

Debug Output


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions