Azure PowerShell Functions in Azure Government

When working with services in Azure Government, often times Azure Government endpoints have to be specified as the defaults for Azure CLI, PowerShell, the Azure SDKs, ect all will default to use the commercial endpoints. This is the same for Azure Functions. To run Azure PowerShell functions to execute the AZ commandlets add the -Environment AzureUSGovernment flag the profile.ps1, similar to what’s seen below.

# Azure Functions profile.ps1
#
# This profile.ps1 will get executed every "cold start" of your Function App.
# "cold start" occurs when:
#
# * A Function App starts up for the very first time
# * A Function App starts up after being de-allocated due to inactivity
#
# You can define helper functions, run commands, or specify environment variables
# NOTE: any variables defined that are not environment variables will get reset after the first execution

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

# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
# Enable-AzureRmAlias

# You can also define functions or aliases that can be referenced in any of your PowerShell functions.