简体   繁体   中英

Azure PowerShell RM Cmdlet AccountAdminLiveEmailId

Is there an RM cmdlet in Azure PowerShell that will return the AccountAdminLiveEmailId?

If you use the classic cmdlets you can use:

Get-AzureSubscription -ExtendedDetails

and this will return an object that includes the AccountAdminLiveEmailId. Unfortunately this is a classic cmdlet so it requires you to login with

Add-AzureAccount

while the RM cmdlets require you to login with

Login-AzureRmAccount

or

Add-AzureRmAccount

We don't want to have people logging in twice so we would be able to access RM and classic cmdlets so we need an RM cmdlet that will get the AccountAdminLiveEmailId. Thank you.

Update:

Using the answer from Jack Zeng I was able to come up with this.

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)
}

You can use the following PowerShell command to get the AccountAdminLiveEmailId.

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

For <admin role> , it depends on your subscription settings. For my case, it's "ServiceAdministrator;AccountAdministrator".It could be "GlobalAdministrator".

This is still Classic Mode, even though it's using an ARM PowerShell. The concept of classic Administrator is retiring. ARM mode encourages you to use Role-Based Access control.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM