简体   繁体   中英

Azure Powershell - How to get a subscription owner email?

I'm trying to run (Get-AzContext).Account.id in a powershell runbook (through the azure portal), to get the email of the currently connected user.

The issue is that the value returned seems to be hidden for some reason. Here's an example of the kind of output I'm receiving " d3f47515-0254-43tv-8060-c824e201088h "

No, it is not been hidden. I suppose you Connect-AzAccount with the service principal in the runbook, not the user account. The d3f47515-0254-43tv-8060-c824e201088h is the Application ID of the service principal.

To confirm this, just run (Get-AzContext).Account.Type , it will return ServicePrincipal .

在此处输入图片说明

If you logged in with a user account, it will return the Userprincipal name (ie email you want, note, strictly speaking it is different from email, but from your description, it should be the one you want)

在此处输入图片说明

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