Set-AzureRmContext

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

Note

The cmdlets referenced in this documentation are for managing legacy Azure resources that use Service Management APIs. See the Az PowerShell module for cmdlets to manage Azure Resource Manager resources.

Syntax

Set-AzureRmContext
   [-SubscriptionName <String>]
   [-TenantId <String>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzureRmContext
   -Context <PSAzureContext>
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-AzureRmContext
   [-TenantId <String>]
   [-SubscriptionId <String>]
   [-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.

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

-SubscriptionId

Specifies the subscription ID for the context that this cmdlet sets for the current session.

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

-SubscriptionName

Specifies the subscription name for the context that this cmdlet sets for the current session.

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

-TenantId

Specifies the ID of the tenant for the context that this cmdlet sets for the current session.

Type:String
Aliases:Domain
Position:Named
Default value:None
Required:False
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

Outputs

PSAzureContext