azure-functions-powershell-worker icon indicating copy to clipboard operation
azure-functions-powershell-worker copied to clipboard

Update profile.ps1 to include the Environment (if available) in Connect-AzAccount

Open Francisco-Gamino opened this issue 4 years ago • 2 comments

This change will be required in all Functions' clients.

This is the current template:

# Authenticate with Azure PowerShell using MSI.
# Remove this if you are not planning on using MSI or Azure PowerShell.
if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) {
    Disable-AzContextAutosave -Scope Process | Out-Null
    Connect-AzAccount -Identity
}

Propose change:

# Authenticate with Azure PowerShell using MSI.
# Remove this if you are not planning on using MSI or Azure PowerShell.
if ($env:MSI_SECRET -and (Get-Module -ListAvailable Az.Accounts)) {
    Disable-AzContextAutosave -Scope Process | Out-Null

    $environmentName = (Get-AzEnvironment).Name
    if ($environmentName)
    {
        Connect-AzAccount -Identity -Environment $environmentName
    }
    else
    {
        Connect-AzAccount -Identity
    }
}

Francisco-Gamino avatar Jun 25 '21 01:06 Francisco-Gamino

Can we use a variable from the Sandbox to figure out the environment?

Francisco-Gamino avatar Jun 28 '21 23:06 Francisco-Gamino

I can't find the link but there was a recommendation to get rid of the -and ( Get-Module -ListAvailable Az.Accounts ) clause to reduce cold start delays

thielj avatar Aug 27 '21 11:08 thielj