Upravit

Sdílet prostřednictvím


Set-AzContext

Sets the tenant, subscription, and environment for cmdlets to use in the current session.

Syntax

Set-AzContext
   [-Context] <PSAzureContext>
   [-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
   [-Name <String>]
   [-Force]
   [-Scope <ContextModificationScope>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzContext
   [-TenantObject] <PSAzureTenant>
   [-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
   [-Name <String>]
   [-Force]
   [-Scope <ContextModificationScope>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzContext
   [-SubscriptionObject] <PSAzureSubscription>
   [-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
   [-Name <String>]
   [-Force]
   [-Scope <ContextModificationScope>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzContext
   [-Tenant <String>]
   [-Subscription] <String>
   [-ExtendedProperty <System.Collections.Generic.IDictionary`2[System.String,System.String]>]
   [-Name <String>]
   [-Force]
   [-Scope <ContextModificationScope>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
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.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Context

Specifies the context for the current session.

Type:PSAzureContext
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-DefaultProfile

The credentials, tenant, and subscription used for communication with azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-ExtendedProperty

Additional context properties

Type:IDictionary<TKey,TValue>[System.String,System.String]
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Force

Overwrite the existing context with the same name, if any.

Type:SwitchParameter
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Name

Name of the context

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters: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.

Type:ContextModificationScope
Accepted values:Process, CurrentUser
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters: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.

Type:String
Aliases:SubscriptionId, SubscriptionName
Position:0
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-SubscriptionObject

A subscription object

Type:PSAzureSubscription
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-Tenant

Tenant domain name or ID

Type:String
Aliases:Domain, TenantId
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-TenantObject

A Tenant Object

Type:PSAzureTenant
Position:0
Default value:None
Required:True
Accept pipeline input:True
Accept wildcard characters:False

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Required:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PSAzureContext

PSAzureTenant

PSAzureSubscription

Outputs

PSAzureContext