Azure PowerShell RM Cmdlet AccountAdminLiveEmailId

Azure PowerShell RM Cmdlet AccountAdminLiveEmailId

Azure PowerShell 中是否有 RM cmdlet return AccountAdminLiveEmailId?

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

Get-AzureSubscription -ExtendedDetails

这将 return 包含 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)
}

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

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

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

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