当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 为 Azure AD 用户设置员工 ID

作者:精品下载站 日期:2024-12-14 09:11:24 浏览:15 分类:玩电脑

为 Azure AD 用户设置员工 ID


您可以更改 Microsoft Azure Active Directory (AAD) 中每个用户的员工 ID。某些 Azure AD 用户甚至没有员工 ID,因此当您找到该字段时,该字段将为空。另一种更快的方法是使用 Microsoft Graph PowerShell 为 Azure AD 用户设置员工 ID。

在本文中,你将了解如何在 Azure AD 门户中设置用户的员工 ID,以及如何获取和设置所有 Azure Active Directory 用户的员工 ID。最后,如何将批量用户员工 ID 导出到单个 CSV 文件。

在 Azure AD 门户中更改员工 ID

所需时间:10 分钟

如何在 Azure AD 中更改用户的员工 ID。

  1. 转到 Azure AD 门户。

    使用您的帐户登录 Microsoft Azure管理员凭据。

    [玩转系统] 为 Azure AD 用户设置员工 ID

  2. 在门户菜单中。

    从门户菜单中,单击“Azure Active”目录。

    [玩转系统] 为 Azure AD 用户设置员工 ID

  3. 您将被重定向到“概述”页面。

    单击“用户”。

    [玩转系统] 为 Azure AD 用户设置员工 ID

  4. 在所有用户(预览)中搜索用户。

    单击用户从列表中。

    [玩转系统] 为 Azure AD 用户设置员工 ID

  5. 用户概览页面。

    单击“编辑属性”。

    [玩转系统] 为 Azure AD 用户设置员工 ID

  6. 在职位信息下查找员工 ID。

    更改或设置新员工身份证号

    [玩转系统] 为 Azure AD 用户设置员工 ID

  7. 已成功更新用户。

    单击“保存”。

    [玩转系统] 为 Azure AD 用户设置员工 ID

您将收到一条通知,表明您已成功更新该特定用户的属性。

验证 Azure AD 中的员工 ID 更新用户

在 Azure AD 中查找用户的员工 ID:

  1. 转到Azure Active Directory > 用户
  2. 单击列表中的用户

[玩转系统] 为 Azure AD 用户设置员工 ID

  1. 点击属性

[玩转系统] 为 Azure AD 用户设置员工 ID

  1. 向下滚动找到新的员工 ID,如下图所示

[玩转系统] 为 Azure AD 用户设置员工 ID

您可以在Azure AD中成功设置任何用户的员工ID!

在下一步中,您将学习使用 PowerShell 获取和设置所有 Azure AD 用户的员工 ID。

使用 PowerShell 设置和获取员工 ID

首先,我们将向您展示如何使用 Microsoft Graph PowerShell 获取和设置单个 Azure AD 用户的员工 ID。然后,您可以批量获取所有 Azure 用户的员工 ID 并将其导出到 CSV 文件。此外,我们还制作了一个脚本来使用 PowerShell 批量设置 Azure AD 用户员工 ID。

连接到 Microsoft Graph PowerShell

1.首先,您需要安装 Microsoft Graph PowerShell 模块,包括Microsoft Graph Beta 模块。建议在 Windows 上安装 PowerShell 7 版本。

注意:您必须安装Microsoft Graph Beta 模块,否则 cmdlet 将无法工作,因为它们在 MS Graph v2.x Final 中不可用。

2. 以管理员身份打开 Windows PowerShell 并运行以下 cmdlet。

Connect-MgGraph -Scope User.ReadWrite.All

3. 将打开登录帐户窗口,您可以在其中选择管理员帐户并输入密码。然后点击登录

[玩转系统] 为 Azure AD 用户设置员工 ID

如果您启用了 MFA,您将收到以短信形式发送或发送到手机上的身份验证应用程序的验证码。如果您的 MFA 被禁用,您将无法在此处执行任何操作。

现在您必须返回 PowerShell 窗口,您将在其中看到此输出。

PS C:\> Connect-MgGraph -Scope User.ReadWrite.All
Welcome To Microsoft Graph!

现在,您可以使用 PowerShell 命令获取和设置所有 Azure 用户的 EmployeeId。

获取单个 Azure AD 用户员工 ID

通过运行以下 PowerShell 命令获取单个用户的 EmployeeID 信息。

Get-MgBetaUser -UserId "[email protected]" | fl employee*

PowerShell 输出显示单个用户的 EmployeeId

EmployeeHireDate      : 
EmployeeId            : 2
EmployeeLeaveDateTime : 
EmployeeOrgData       : Microsoft.Graph.PowerShell.Models.MicrosoftGraphEmployeeOrgData
EmployeeType          : 

它显示用户 Brenda Smith 具有 EmployeeId 2

设置单个 Azure AD 用户员工 ID

假设我们要更改单个用户的员工 ID。在我们的示例中,我们希望将 Brenda Smith 的 EmployeeId 更改为数字 22

注意:设置 Azure 用户的 EmployeeID 时,您可以键入数字和字母。

1. 使用以下 PowerShell 语法键入单个用户的 UserId (UPN) 并键入 EmployeeId您要设置的新号码

Update-MgBetaUser -UserId "UserPrincipalName" -EmployeeId "new number"

2. 运行PowerShell命令更改单个用户的EmployeeId。在我们的示例中,我们希望将 Brenda Smith 的 EmployeeId 更改为数字 22

Update-MgBetaUser -UserId "[email protected]" -EmployeeId "22"

3. 验证您是否更新了该单个用户的 EmployeeId。

Get-MgBetaUser -UserId "[email protected]" | fl EmployeeId

PowerShell 输出显示该单个用户的更新后的 EmployeeId。在我们的示例中,我们为 Brenda Smith 设置了新的 EmployeeId 22

PS C:\> Get-MgBetaUser -UserId "[email protected]" | fl EmployeeId

EmployeeId : 22

您为单个用户正确设置了新的员工 ID。接下来,我们将向您展示如何获取所有用户的EmployeeId。

批量获取Azure AD用户员工ID

要获取批量用户员工 ID,请运行以下 PowerShell 命令。

Get-MgBetaUser -All | ft UserPrincipalName, Displayname, EmployeeId

PowerShell 输出显示以下结果。

PS C:\> Get-MgBetaUser -All | ft UserPrincipalName, Displayname, EmployeeId

UserPrincipalName           DisplayName     EmployeeId
-----------------           -----------     ----------
[email protected]          M365info Admin            
[email protected]  Amanda Hansen   1         
[email protected]   Brenda Smith    2         
[email protected]    Chris Lucas     3         
[email protected]     David Kent      4         
[email protected]    Diana Baker     5         
[email protected]  George Wilson             
[email protected]	    René Gibs	              
[email protected] Stephen Hunter            
[email protected]    Susan Brown               

将批量 Azure AD 用户员工 ID 导出到 CSV 文件

您可以将所有 Azure 用户的员工 ID 导出到单个 CSV 文件。这样,您就可以轻松地搜索到每个用户拥有哪个员工 ID 号。

运行以下 PowerShell 命令将批量用户的 EmployeeId 导出到 CSV 文件。

Get-MgBetaUser -All | Select-Object UserPrincipalName, DisplayName, EmployeeId | Export-Csv -Path "C:\temp\UsersEmployeeID.csv" -NoTypeInformation -Encoding UTF8

您将在 C:\temp 文件夹中找到 CSV 文件。使用 Microsoft Excel 等应用程序打开 CSV 文件以查看结果。

[玩转系统] 为 Azure AD 用户设置员工 ID

批量设置 Azure AD 用户员工 ID

要使用 PowerShell 批量设置多个 Azure AD 用户员工 ID,您需要创建一个 CSV 文件。

打开记事本并键入以下数据以更改或设置多个 Azure AD 用户的员工 ID。

  1. 在顶部输入 UserPrincipalName,EmployeeID
  2. 列出Azure AD 用户
  3. 设置更新的EmployeeID

注意:要分隔单词,您必须在 CSV 文件中键入逗号 (,) 作为分隔符,且不带空格。

下图是 CSV 文件外观的示例。

[玩转系统] 为 Azure AD 用户设置员工 ID

  1. 如果 (C:) 驱动器中还没有文件夹 temp,请创建该文件夹
  2. 将文件命名为UsersID.csv
  3. 保存类型所有文件 (*)
  4. 点击保存

[玩转系统] 为 Azure AD 用户设置员工 ID

  1. 下一步是下载 Set-EmployeeID.ps1 PowerShell 脚本。
  2. 或者将以下脚本复制并粘贴到记事本中,并将其另存为 Set-EmployeeID.ps1 文件。
<#
    .SYNOPSIS
    .\Set-EmployeeID.ps1

    .DESCRIPTION
    The script will set/update the employee ID for Azure AD users.

    .LINK
    o365info.com/set-employee-id-azure

    .NOTES
    Written By: o365info
    Website:    o365info.com

    .CHANGELOG
    V1.00, 06/01/2023 - Initial version
#>

# Connect to Microsoft Graph
Connect-MgGraph -Scope User.ReadWrite.All

# Read the CSV file
$users = Import-Csv -Path "C:\temp\UsersID.csv"

# Go through each user in the CSV and update the EmployeeId property
foreach ($user in $users) {
    $userPrincipalName = $user.UserPrincipalName
    $employeeId = $user.EmployeeId

    # Check if the user exists
    $existingUser = Get-MgBetaUser -UserId $userPrincipalName -ErrorAction SilentlyContinue

    if ($existingUser) {
        # Check if the existing EmployeeId matches the new value
        if ($existingUser.EmployeeId -eq $employeeId) {
            # EmployeeId already set with the same value
            Write-Host "User '$userPrincipalName' already has Employee ID '$employeeId'." -ForegroundColor Cyan
        }
        else {
            # Update the EmployeeId
            Update-MgBetaUser -UserId $userPrincipalName -EmployeeId $employeeId
            Write-Host "User '$userPrincipalName' updated Employee ID '$employeeId'successfully." -ForegroundColor Green
        }
    }
    else {
        # User not found
        Write-Host "User '$userPrincipalName' not found and couldn't set Employee ID $employeeId." -ForegroundColor Red
    }
}
  1. 如果您还没有,请在(C:)驱动器中创建文件夹scripts
  2. 将 Set-EmployeeID.ps1 PowerShell 脚本保存C:\scripts 文件夹中

打开文件检查是否已解锁,防止运行脚本时出错。

[玩转系统] 为 Azure AD 用户设置员工 ID

在 PowerShell 中运行脚本,输出将类似于以下示例结果。

Set-EmployeeID.ps1 脚本将显示以下内容:

  • 如果用户已经具有相同的员工 ID
  • 如果用户员工ID设置成功
  • 如果在 Azure AD 中找不到该用户
Welcome To Microsoft Graph!
User '[email protected]' already has Employee ID '2'.
User '[email protected]' updated Employee ID '5abc'successfully.
User '[email protected]' updated Employee ID '6'successfully.
User '[email protected]' updated Employee ID '10'successfully.
User '[email protected]' updated Employee ID '15'successfully.
User '[email protected]' not found and couldn't set Employee ID 13.

就是这样!您已成功使用 PowerShell 批量获取和设置所有 Azure 用户的员工 ID。

了解更多:使用 PowerShell 管理用户邮箱 »

结论

你了解了如何在 Azure AD 门户中和使用 PowerShell 为 Azure AD 用户设置员工 ID。可以轻松找到 Azure AD 用户员工 ID 并编辑其属性。您还可以批量获取用户的员工 ID 并将所有信息导出到 CSV 文件。

您喜欢这篇文章吗?您可能还喜欢在 Azure AD 中创建无限的客户端密钥。不要忘记关注我们并分享这篇文章。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯