你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Select-AzContext

在 Azure PowerShell cmdlet 中选择要面向的订阅和帐户

语法

SelectByInputObject (默认值)

Select-AzContext
    -InputObject <PSAzureContext>
    [-Scope <ContextModificationScope>]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

SelectByName

Select-AzContext
    [-Name] <String>
    [-Scope <ContextModificationScope>]
    [-DefaultProfile <IAzureContextContainer>]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

说明

在 Azure PowerShell cmdlet 中选择目标(或帐户或租户)的订阅。 在此 cmdlet 之后,未来的 cmdlet 将面向所选上下文。

示例

示例 1:面向命名上下文

Select-AzContext "Work"
Name    Account             SubscriptionName    Environment         TenantId
----    -------             ----------------    -----------         --------
Work    test@outlook.com    Subscription1       AzureCloud          xxxxxxxx-x...

面向“工作”上下文中帐户、租户和订阅的未来 Azure PowerShell cmdlet。

示例 2

在此 PowerShell 会话中,选择要在 Azure PowerShell cmdlet 中面向的订阅和帐户。 (autogenerated)

Select-AzContext -Name TestEnvironment -Scope Process

参数

-Confirm

在运行 cmdlet 之前,提示你进行确认。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False
别名:cf

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-DefaultProfile

用于与 Azure 通信的凭据、租户和订阅

参数属性

类型:IAzureContextContainer
默认值:None
支持通配符:False
不显示:False
别名:AzContext, AzureRmContext, AzureCredential

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-InputObject

上下文对象,通常通过管道传递。

参数属性

类型:PSAzureContext
默认值:None
支持通配符:False
不显示:False

参数集

SelectByInputObject
Position:Named
必需:True
来自管道的值:True
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Name

上下文的名称

参数属性

类型:String
默认值:None
支持通配符:False
不显示:False

参数集

SelectByName
Position:0
必需:True
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-Scope

确定上下文更改的范围,例如,更改仅适用于当前进程或此用户启动的所有会话

参数属性

类型:ContextModificationScope
默认值:None
接受的值:Process, CurrentUser
支持通配符:False
不显示:False

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

-WhatIf

显示 cmdlet 运行时会发生什么情况。 命令脚本未运行。

参数属性

类型:SwitchParameter
默认值:None
支持通配符:False
不显示:False
别名:无线

参数集

(All)
Position:Named
必需:False
来自管道的值:False
来自管道的值(按属性名称):False
来自剩余参数的值:False

CommonParameters

此 cmdlet 支持通用参数:-Debug、-ErrorAction、-ErrorVariable、-InformationAction、-InformationVariable、-OutBuffer、-OutVariable、-PipelineVariable、-ProgressAction、-Verbose、-WarningAction 和 -WarningVariable。 有关详细信息,请参阅 about_CommonParameters

输入

PSAzureContext

输出

PSAzureContext