如何在Windows Powershell中获取Azure Active Directory用户名?

时间:2017-04-16 23:44:45

标签: powershell azure azure-active-directory

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

我已尝试过this question处的提示,但这些提示似乎都不适用于加入Azure Active Directory的计算机。

e.g。对于用户:Jonathan Doe, john@example.com,您只能获得用户的正确姓名& AzureAD(不是他们的用户名或“真实”域名):

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

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

2 个答案:

答案 0 :(得分:3)

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

{
  "name": "genesis",
  "version": "0.0.0",
  "description": "Small description for genesis goes here",
  "license": "MIT",
  "author": "",
  "directories": {
    "doc": "doc",
    "test": "tests"
  },
  "repository": "",
  "scripts": {
    "build": "ember build",
    "start": "ember server",
    "test": "ember test"
  },
  "devDependencies": {
    "broccoli-asset-rev": "2.5.x",
    "ember-cli": "2.12.x",
    "ember-cli-app-version": "2.0.x",
    "ember-cli-babel": "5.2.x",
    "ember-cli-dependency-checker": "1.3.x",
    "ember-cli-htmlbars": "1.1.x",
    "ember-cli-htmlbars-inline-precompile": "0.3.x",
    "ember-cli-inject-live-reload": "1.6.x",
    "ember-cli-jshint": "2.0.x",
    "ember-cli-qunit": "3.1.x",
    "ember-cli-release": "0.2.x",
    "ember-cli-shims": "1.0.x",
    "ember-cli-sri": "2.1.x",
    "ember-cli-test-loader": "1.1.x",
    "ember-cli-tutorial-style": "0.0.x",
    "ember-cli-uglify": "1.2.x",
    "ember-data": "2.12.x",
    "ember-export-application-global": "1.1.x",
    "ember-load-initializers": "0.6.x",
    "ember-resolver": "2.1.x",
    "ember-simple-auth": "1.2.x",
    "ember-simple-auth-token": "2.1.x",
    "ember-source": "2.11.x",
    "ember-welcome-page": "2.0.x",
    "loader.js": "4.2.x",
    "typeface-fira-sans": "0.0.x"
  },
  "engines": {
    "node": ">= 0.12.0"
  },
  "private": true,
  "dependencies": {
    "font-awesome": "4.7.x",
    "lato-font": "3.0.x",
    "semantic-ui-ember": "^2.0.1",
    "socket.io-client": "1.7.x"
  }
}

此外,该程序' whoami.exe'提供了许多其他参数来获取有关当前用户的其他信息。您可以输入以下命令,以获取有关' whoami.exe'。

的更多详细信息
whoami.exe /UPN

答案 1 :(得分:1)

我不确定这是多么正式,但我在注册表中找到了一个包含用户名user@company.com的链接。这是HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\IdentityStore\Cache\xxx\IdentityCache\xxx.下的关键名称是UserName。您可以使用built-in powershell registry provider导航到此注册表项。