如何在 Windows Powershell 中获取 Azure Active Directory 用户名? [英] How to get an Azure Active Directory username in Windows Powershell?

查看:36
本文介绍了如何在 Windows Powershell 中获取 Azure Active Directory 用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取当前的 Windows 用户名 &来自 Windows 10 Azure Active Directory (AAD) 加入计算机上的 Powershell 的域.

I'm trying to get the current Windows username & domain from Powershell on a Windows 10 Azure Active Directory (AAD) joined machine.

我已经尝试过这个问题中的提示,但它们似乎都不适用于加入 Azure Active Directory 的计算机.

I've tried the tips at this question, but none of them seem to work for Azure Active Directory-joined machines.

例如对于用户:Jonathan Doe, john@example.com 你只会得到用户的专有名称 &AzureAD(不是他们的用户名或真实"域):

e.g. for the user: Jonathan Doe, john@example.com you'll get only the users' proper name & AzureAD (not their username or 'real' domain):

$env:UserName --> JonathanDoe
$env:UserDomain --> AzureAD
[System.Security.Principal.WindowsIdentity]::GetCurrent().Name --> AzureAD\JonathanDoe

有谁知道如何获取用户实际凭据或特定 Azure AAD 域的任何部分?(例如 johnexample.com 或理想情况下 john@example.com)

Does anyone know how to get any part of the user's actual credential or specific Azure AAD domain? (e.g. john or example.com or ideally john@example.com)

推荐答案

您可以在 PowerShell 中运行以下命令,输出将以 UPN 格式显示用户名.您可以从中获取用户名和域名.

You can run the following command in PowerShell, the output will display the user name in UPN format.You can get both of the username and domain name from that.

whoami.exe /UPN

此外,程序whoami.exe"提供了许多其他参数,用于获取有关当前用户的其他信息.您可以键入以下命令以获取有关whoami.exe"的更多详细信息.

In addition, the program 'whoami.exe' provides many other parameters for getting additional information about current user. You can type the following command for more details about 'whoami.exe'.

whoami.exe /?

这篇关于如何在 Windows Powershell 中获取 Azure Active Directory 用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆