Azure PowerShell RM Cmdlet AccountAdminLiveEmailId

时间:2016-05-19 15:55:00

标签: powershell azure azure-powershell

Azure PowerShell中是否有RM cmdlet将返回AccountAdminLiveEmailId?

如果您使用经典cmdlet,则可以使用:

Get-AzureSubscription -ExtendedDetails

这将返回一个包含AccountAdminLiveEmailId的对象。不幸的是,这是一个经典的cmdlet,因此需要您使用

登录
Add-AzureAccount

虽然RM cmdlet要求您使用

登录
Login-AzureRmAccount

Add-AzureRmAccount

我们不希望让人们登录两次,因此我们可以访问RM和经典cmdlet,因此我们需要一个RM cmdlet来获取AccountAdminLiveEmailId。谢谢。

更新

使用Jack Zeng的答案,我能够想出这个。

Login-AzureRmAccount

$Subscriptions = Get-AzureRmSubscription

$Emails = New-Object System.Collections.ArrayList

foreach($Subscription in $Subscriptions)
{
    Set-AzureRmContext -TenantId $Subscription.TenantId -SubscriptionId $Subscription.SubscriptionId

    $Email = Get-AzureRmRoleAssignment -IncludeClassicAdministrators | where {$_.RoleDefinitionName -eq "ServiceAdministrator;AccountAdministrator"} | Select DisplayName

    $Emails.Add($Email)
}

1 个答案:

答案 0 :(得分:0)

您可以使用以下PowerShell命令获取AccountAdminLiveEmailId。

Get-AzureRmRoleAssignment -IncludeClassicAdministrators | where {$_.RoleDefinitionName -eq "<admin role>"}

对于<admin role>,这取决于您的订阅设置。对于我的情况,它是“ServiceAdministrator; AccountAdministrator”。它可以是“GlobalAdministrator”。

这仍然是经典模式,即使它使用的是ARM PowerShell。经典管理员的概念即将退休。 ARM模式鼓励您使用基于角色的访问控制。