Edit

Share via


Set-AzContext

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    [email protected]    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

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Context

Specifies the context for the current session.

Parameter properties

Type:PSAzureContext
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

Context
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-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

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-ExtendedProperty

Additional context properties

Parameter properties

Type:

IDictionary<TKey,TValue>[System.String,System.String]

Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-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

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-Name

Name of the context

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-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

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-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

Subscription
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-SubscriptionObject

A subscription object

Parameter properties

Type:PSAzureSubscription
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

SubscriptionObject
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-Tenant

Tenant domain name or ID

Parameter properties

Type:String
Default value:None
Supports wildcards:False
DontShow:False
Aliases:Domain, TenantId

Parameter sets

Subscription
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-TenantObject

A Tenant Object

Parameter properties

Type:PSAzureTenant
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

TenantObject
Position:0
Mandatory:True
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

-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

(All)
Position:Named
Mandatory:False
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

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