批量删除 Azure Active Directory 中的用户Bulk delete users in Azure Active Directory

在 Azure Active Directory (Azure AD) 门户中,可使用逗号分隔值 (CSV) 文件批量删除用户,从而将大量成员从组中删除。Using Azure Active Directory (Azure AD) portal, you can remove a large number of members to a group by using a comma-separated values (CSV) file to bulk delete users.

了解 CSV 模板Understand the CSV template

下载并填写 CSV 模板,该模板可帮助你成功批量删除 Azure AD 用户。Download and fill in the CSV template to help you successfully delete Azure AD users in bulk. 下载的 CSV 模板可能如下例所示:The CSV template you download might look like this example:

用于上传和调出的电子表格,说明了每一行和每一列的用途和值

CSV 模板结构CSV template structure

下载的 CSV 模板中的行如下所示:The rows in a downloaded CSV template are as follows:

  • 版本号 :包含版本号的第一行必须包含在上传的 CSV 中。Version number : The first row containing the version number must be included in the upload CSV.
  • 列标题:列标题的格式为:<项名称> [PropertyName] <必需或空白>。Column headings : The format of the column headings is <Item name> [PropertyName] <Required or blank>. 例如,User name [userPrincipalName] RequiredFor example, User name [userPrincipalName] Required. 某些较旧版本的模板可能会略有不同。Some older versions of the template might have slight variations.
  • 示例行:我们已经在模板中包含了一行示例,说明每列可接受的值。Examples row : We have included in the template a row of examples of acceptable values for each column. 必须删除示例行并将其替换为你自己的项。You must remove the examples row and replace it with your own entries.

其他指南Additional guidance

  • 不得删除或修改上传模板的前两行,否则无法处理上传。The first two rows of the upload template must not be removed or modified, or the upload can't be processed.
  • 所需的列会先列出。The required columns are listed first.
  • 建议不要将新列添加到模板。We don't recommend adding new columns to the template. 所添加的任何其他列都会被忽略,不进行处理。Any additional columns you add are ignored and not processed.
  • 建议尽可能经常下载 CSV 模板的最新版本。We recommend that you download the latest version of the CSV template as often as possible.

批量删除用户To bulk delete users

  1. 使用组织中的用户管理员帐户登录到 Azure AD 组织Sign in to your Azure AD organization with an account that is a User administrator in the organization.

  2. 在 Azure AD 中,选择“用户” > “批量删除”。In Azure AD, select Users > Bulk delete.

  3. 在“批量删除用户”页上,选择“下载”以接收一个有效的包含用户属性的 CSV 文件。On the Bulk delete user page, select Download to receive a valid CSV file of user properties.

    选择可在其中列出要删除的用户的本地 CSV 文件

  4. 打开 CSV 文件,并为每个要删除的用户添加一行。Open the CSV file and add a line for each user you want to delete. 唯一需要的值为“用户主体名称”。The only required value is User principal name. 然后保存文件。Then save the file.

    CSV 文件包含要删除的用户的名称和 ID

  5. 在“批量删除用户”页的“上传 csv 文件”下,浏览到该文件。On the Bulk delete user page, under Upload your csv file , browse to the file. 选择该文件并单击“提交”后,将启动对 CSV 文件的验证。When you select the file and click submit, validation of the CSV file starts.

  6. 验证文件内容后,会看到“文件上传成功”消息。When the file contents are validated, you’ll see File uploaded successfully. 如果有错误,必须修正错误,然后才能提交作业。If there are errors, you must fix them before you can submit the job.

  7. 文件通过验证后,请选择“提交”,以启动用于删除用户的 Azure 批量操作。When your file passes validation, select Submit to start the Azure bulk operation that deletes the users.

  8. 删除操作完成后,会显示一条通知,指出批量操作成功。When the deletion operation completes, you'll see a notification that the bulk operation succeeded.

如果有错误,可以在“批量操作结果”页下载并查看结果文件。If there are errors, you can download and view the results file on the Bulk operation results page. 该文件包含每个错误的原因。The file contains the reason for each error.

查看状态Check status

可在“批量操作结果”页中查看所有挂起的批量请求的状态。You can see the status of all of your pending bulk requests in the Bulk operation results page.

在“批量操作结果”页中查看删除状态。Check delete status in the Bulk Operations Results page.

接下来,可通过 Azure 门或 PowerShell 查看已删除的用户是否存在于 Azure AD 组织中。Next, you can check to see that the users you deleted exist in the Azure AD organization either in the Azure portal or by using PowerShell.

在 Azure 门户中验证已删除的用户Verify deleted users in the Azure portal

  1. 使用组织中的用户管理员的帐户登录到 Azure 门户。Sign in to the Azure portal with an account that is a User administrator in the organization.
  2. 在导航窗格中选择“Azure Active Directory”。In the navigation pane, select Azure Active Directory.
  3. 在“管理”下,选择“用户” 。Under Manage , select Users.
  4. 在“显示”下仅选择“所有用户”,验证已删除的用户是否不再列出。Under Show , select All users only and verify that the users you deleted are no longer listed.

使用 PowerShell 验证已删除的用户Verify deleted users with PowerShell

运行以下命令:Run the following command:

Get-AzureADUser -Filter "UserType eq 'Member'"

验证已删除的用户是否不再列出。Verify that the users that you deleted are no longer listed.

后续步骤Next steps