Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Set-AzContext
- Module:
- Az.Accounts Module
Sets the tenant, subscription, and environment for cmdlets to use in the current session.
Syntax
Context (Default)
Set-AzContext
[-Context] <PSAzureContext>
[-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-Name <String>]
[-Force]
[-Scope <ContextModificationScope>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
TenantObject
Set-AzContext
[-TenantObject] <PSAzureTenant>
[-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-Name <String>]
[-Force]
[-Scope <ContextModificationScope>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
SubscriptionObject
Set-AzContext
[-SubscriptionObject] <PSAzureSubscription>
[-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-Name <String>]
[-Force]
[-Scope <ContextModificationScope>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Subscription
Set-AzContext
[-Subscription] <String>
[-Tenant <String>]
[-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-Name <String>]
[-Force]
[-Scope <ContextModificationScope>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
TenantNameOnly
Set-AzContext
-Tenant <String>
[-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
[-Name <String>]
[-Force]
[-Scope <ContextModificationScope>]
[-DefaultProfile <IAzureContextContainer>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Set-AzContext cmdlet sets authentication information for cmdlets that you run in the current session. The context includes tenant, subscription, and environment information.
Examples
Example 1: Set the subscription context
Set-AzContext -Subscription "xxxx-xxxx-xxxx-xxxx"
Name Account SubscriptionName Environment TenantId
---- ------- ---------------- ----------- --------
Work test@outlook.com Subscription1 AzureCloud xxxxxxxx-x...
This command sets the context to use the specified subscription.
Parameters
-Confirm
Prompts you for confirmation before running the cmdlet.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | cf |
Parameter sets
-Context
Specifies the context for the current session.
Parameter properties
| Type: | PSAzureContext |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-DefaultProfile
The credentials, tenant, and subscription used for communication with azure.
Parameter properties
| Type: | IAzureContextContainer |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
Parameter sets
-ExtendedProperty
Additional context properties
Parameter properties
| Type: | IDictionary<TKey,TValue>[System.String,System.String] |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Force
Overwrite the existing context with the same name, if any.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Name
Name of the context
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Scope
Determines the scope of context changes, for example, whether changes apply only to the current process, or to all sessions started by this user.
Parameter properties
| Type: | ContextModificationScope |
| Default value: | None |
| Accepted values: | Process, CurrentUser |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Subscription
The name or id of the subscription that the context should be set to. This parameter has aliases to -SubscriptionName and -SubscriptionId, so, for clarity, either of these can be used instead of -Subscription when specifying name and id, respectively.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | SubscriptionId, SubscriptionName |
Parameter sets
-SubscriptionObject
A subscription object
Parameter properties
| Type: | PSAzureSubscription |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Tenant
Tenant domain name or ID
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | Domain, TenantId |
Parameter sets
-TenantObject
A Tenant Object
Parameter properties
| Type: | PSAzureTenant |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Parameter properties
| Type: | SwitchParameter |
| Default value: | False |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | wi |
Parameter sets
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
PSAzureContext
PSAzureTenant
PSAzureSubscription
Outputs
PSAzureContext
Related Links
Azure PowerShell
Feedback
Was this page helpful?
