The Azure context returned as part of this sign in is valid for the current session only and Sign in using -Scope Process with Connect-AzAccount. Save Azure contexts across PowerShell sessionsīy default, Azure contexts are saved for use between PowerShell sessions. Run Azure PowerShell cmdlets in PowerShell Jobs. More about running PowerShell Jobs using Azure PowerShell, see The other main use of contexts with Azure PowerShell cmdlets is to run background commands. New-AzVM -Name ExampleVM -AzContext $context To avoid switching contexts for a whole PowerShell session, all Azure PowerShell commands can be runĪgainst a given context with the AzContext parameter: $context = Get-AzContext -Name "mycontext" Scope lets you change a single session's active context without changing your default: Get-AzContext -Name 'mycontext' | Select-AzContext -Scope Process Select-AzContext support the Scope parameter so that you can control how long the context isĪctive. Like many other account and context management commands in Azure PowerShell, Set-AzContext and Get-AzContext -Name 'mycontext' | Select-AzContext # Set a context with a piped Azure context object
Using Set-AzContext -Context, but is designed for use with piping: Set-AzContext -Context $(Get-AzContext -Name 'mycontext') # Set a context with an inline Azure context object Select-AzContext is meant to be used only with existing Azure contexts and works similarly to Set-AzContext creates a new Azure context for a subscription if one doesn't exist, and then Change the active Azure contextīoth Set-AzContext and Select-AzContext can be In the format Subscription Name (subscription-id). If the Name parameter is omitted, then the subscription's name and ID are used as the context name Or give the subscription name or ID and the tenant ID if necessary: Set-AzContext -Name 'M圜ontextName' -Subscription 'MySubscriptionName' -Tenant '00000000-0000-0000-0000-000000000000' Get-AzSubscription as a piped value and configure a new Azure context: Get-AzSubscription -SubscriptionName 'MySubscriptionName' | The cmdlet is designed to take the output object from To use existing subscription information. The easiest way to create a new Azure context is The Set-AzContext cmdlet is used to both create newĪzure contexts and set them as the active context. Create a new Azure context from subscription information The available Azure contexts aren't always your available subscriptions. Or get a context by name: Get-AzContext -Name 'mycontext'Ĭontext names may be different from the name of the associated subscription. List all of the availableĬontexts with the ListAvailable parameter: Get-AzContext -ListAvailable Get Azure contextsĪvailable Azure contexts are retrieved with the The object returned by Connect-AzAccount is the default Azure context used for the When you sign in with Connect-AzAccount, at least one Azure context is created for your default This token is stored and how long it persists for is determined by theĪuthentication tokens used by Azure contexts are the same as other stored tokens that are part of a A reference to a token cache, a stored authentication token for accessing an Azure cloud.Tenants are often referred to as organizations inĭocumentation or when working with Active Directory. The active subscription, a service agreement with Microsoft to create and run Azure resources,.Azure contexts treat users,Īpplication IDs, and service principals the same from an account perspective. The account that was used to sign in to Azure withĬonnect-AzAccount.PowerShell doesn't need to reauthenticate your account each time you switch subscriptions. Overview of Azure context objectsĪzure contexts are PowerShell objects representing your active subscription to run commands against,Īnd the authentication information needed to connect to an Azure cloud. Use Azure PowerShell cmdlets in PowerShell jobs after becoming familiar withĪzure contexts. Running background or parallel tasks, see You're looking to manage users, subscriptions, tenants, or other account information, see theĪzure Active Directory documentation. This article covers managing Azure contexts, not the management of subscriptions or accounts. Information across multiple PowerShell sessions and run background tasks. Azure contexts are also used to store sign-in The subscription to run Azure PowerShell cmdlets on. If you have more than one subscription, Azure contexts let you select Azure PowerShell uses Azure PowerShell context objects (Azure contexts) to hold subscription andĪuthentication information.