Set-AzureRmContext

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

Syntax

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

PS C:\>Set-AzureRmContext -SubscriptionId "xxxx-xxxx-xxxx-xxxx"

Account      : PFuller@contoso.com
Environment  : AzureCloud
Subscription : xxxx-xxxx-xxxx-xxxx
Tenant       : yyyy-yyyy-yyyy-yyyy

This command sets the context to use the specified subscription.

Required Parameters

-Context

Specifies the context for the current session.

Type:Microsoft.Azure.Commands.Profile.Models.PSAzureContext
Position:0
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-Subscription

Subscription Name or Id

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

A subscription object

Type:Microsoft.Azure.Commands.Profile.Models.PSAzureSubscription
Position:0
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-TenantObject

A Tenant Object

Type:Microsoft.Azure.Commands.Profile.Models.PSAzureTenant
Position:0
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False

Optional Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:System.Management.Automation.SwitchParameter
Aliases:cf
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

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

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.IAzureContextContainer
Aliases:AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ExtendedProperty

Additional context properties

Type:System.Collections.Generic.IDictionary`2[System.String,System.String]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Force

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

Type:System.Management.Automation.SwitchParameter
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Name

Name of the context

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Scope

Determines the scope of context changes, for example, wheher changes apply only to the cusrrent process, or to all sessions started by this user.

Type:Microsoft.Azure.Commands.Profile.Common.ContextModificationScope
Parameter Sets:Process, CurrentUser
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Tenant

Tenant name or ID

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

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

Type:System.Management.Automation.SwitchParameter
Aliases:wi
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

PSAzureContext

Parameter 'Context' accepts value of type 'PSAzureContext' from the pipeline

Outputs

PSAzureContext