适用于现有设备的 Windows Autopilot 部署:为 Windows Autopilot 配置文件创建 JSON 文件

Windows Autopilot 用户驱动的 Microsoft Entra 加入步骤:

  • 步骤 3:为 Windows Autopilot 配置文件创建 JSON 文件

有关现有设备工作流的 Windows Autopilot 部署概述,请参阅 Intune 和 Configuration Manager 中现有设备的 Windows Autopilot 部署

为 Windows Autopilot 配置文件创建 JSON 文件

注意

本部分中的 PowerShell 代码片段已于 2023 年 7 月更新,以使用 Microsoft Graph PowerShell 模块,而不是已弃用的 AzureAD Graph PowerShell 模块。 Microsoft Graph PowerShell 模块首次使用时可能需要审批 Microsoft Entra ID 中的其他权限。 有关详细信息,请参阅 AzureAD重要提示:Azure AD Graph 停用和 PowerShell 模块弃用

安装适当的模块以允许从 Intune 导出 Windows Autopilot 配置文件后,下一步是将 Windows Autopilot 配置文件导出为 JSON 文件。 JSON 文件用于在 Configuration Manager 中创建程序包。

若要将 Windows Autopilot 配置文件导出为 JSON 文件,请执行以下步骤:

  1. 登录到 Configuration Manager 站点服务器或其他设备,其中安装了所需模块以从 Intune 获取 Windows Autopilot 配置文件 步骤。

  2. 在设备上,以管理员身份打开 PowerShell 窗口,方法是右键单击“开始”菜单并选择“Windows PowerShell (管理员) /Windows 终端 (管理员) ”,然后在“用户帐户控制” (UAC) 提示处选择“”。

  3. 通过选择以下 PowerShell 代码块右上角的“复制”来复制以下命令:

    Connect-MgGraph -Scopes "Device.ReadWrite.All", "DeviceManagementManagedDevices.ReadWrite.All", "DeviceManagementServiceConfig.ReadWrite.All", "Domain.ReadWrite.All", "Group.ReadWrite.All", "GroupMember.ReadWrite.All", "User.Read"
    $AutopilotProfile = Get-AutopilotProfile
    $targetDirectory = "C:\Autopilot"
    $AutopilotProfile | ForEach-Object {
        New-Item -ItemType Directory -Path "$targetDirectory\$($_.displayName)"
        $_ | ConvertTo-AutopilotConfigurationJSON | Set-Content -Encoding Ascii "$targetDirectory\$($_.displayName)\AutopilotConfigurationFile.json"
    }
    
  4. 将命令粘贴到提升权限的 PowerShell 窗口中,然后在键盘上选择 Enter 以运行命令。 如果提升的 PowerShell 命令窗口尚未登录到 Intune,则将显示“登录到帐户”窗口。 使用有权访问 Intune 和 Windows Autopilot 配置文件的 Microsoft Entra 帐户登录。

  5. 登录到 Intune 后,可能需要再次选择 Enter 才能运行代码块中的最后一个命令。

  6. 成功运行所有命令后,Windows Autopilot 配置文件将显示在变量指定的 $targetDirectory 文件夹下的子文件夹中。 默认情况下,变量为 $targetDirectoryC:\AutoPilot,但如果需要,可以将其更改为其他位置。 子文件夹具有来自 Intune 的 Windows Autopilot 配置文件的名称。 如果有多个 Windows Autopilot 配置文件,则每个配置文件都有其自己的子文件夹。 在每个文件夹中,都有一个名为 AutopilotConfigurationFile.json的 JSON 文件。

注意

上述脚本从 Intune 导出所有 Windows Autopilot 配置文件。 除了受支持的用户驱动 Windows Autopilot 配置文件外,它还会下载不受支持的预预配 Windows Autopilot 配置文件和自部署 Windows Autopilot 配置文件(如果存在于环境中)。

下一步:在 Configuration Manager 中为 JSON 文件创建和分发包

有关创建 JSON 文件的详细信息,请参阅以下文章: