为组织内的用户预设置 OneDrivePre-provision OneDrive for users in your organization

默认情况下,用户首次浏览到其 OneDrive 时,系统会自动为用户预配它。By default, the first time that a user browses to their OneDrive it's automatically provisioned for them. 在某些情况下(如以下情况)你可能希望用户的 OneDrive 位置事先准备就绪或预设置:In some cases, such as the following, you might want your users' OneDrive locations to be ready beforehand, or pre-provisioned:

  • 你的组织具有添加新员工的自定义流程,并且你想要在添加新员工时创建 OneDrive。Your organization has a custom process for adding new employees, and you want to create a OneDrive when you add a new employee.

  • 你的组织计划从本地 SharePoint Server 迁移到 Microsoft 365。Your organization plans to migrate from SharePoint Server on-premises to Microsoft 365.

  • 您的组织计划从另一个联机存储服务迁移。Your organization plans to migrate from another online storage service.

本文介绍如何使用 PowerShell 为用户预设置 OneDrive。This article describes how to pre-provision OneDrive for your users by using PowerShell.

重要

必须允许预预配的用户帐户登录,并且还必须分配有 SharePoint 许可证。The user accounts that you are pre-provisioning must be allowed to sign in and must also have a SharePoint license assigned. 若要使用此 cmdlet 预配 OneDrive,您必须是全局管理员或 SharePoint 管理员,并且必须分配有 SharePoint 许可证。To provision OneDrive by using this cmdlet, you must be a global or SharePoint administrator and must be assigned a SharePoint license.

为用户预设置 OneDrivePre-provision OneDrive for users

  1. 如果要为许多用户预预配 OneDrive,请创建这些用户的列表并将其另存为文件。If you're pre-provisioning OneDrive for many users, create a list of these users and save it as a file. 例如,创建一个名为 Users.txt 的文本文件,其中包含:For example, create a text file named Users.txt that contains:

    user1@contoso.com
    user2@contoso.com
    user3@contoso.com
    
  2. 下载最新的SharePoint在线管理壳Download the latest SharePoint Online Management Shell.

    备注

    如果你已安装早期版本的SharePoint Online Management Shell,请进入添加或删除程序并卸载 "SharePoint Online Management Shell"。If you installed a previous version of the SharePoint Online Management Shell, go to Add or remove programs and uninstall "SharePoint Online Management Shell."

    在 "下载中心" 页面上,选择你的语言,然后单击 "下载" 按钮。On the Download Center page, select your language and then click the Download button. 系统会要求你下载 x64 和 x86 .msi 文件之间做出选择。You'll be asked to choose between downloading a x64 and x86 .msi file. 如果你运行的是64位版本的Windows,请下载x64文件,如果你运行的是32位版本,请下载x86文件。Download the x64 file if you're running the 64-bit version of Windows or the x86 file if you're running the 32-bit version. 如果你不知道,请参阅我运行的是哪个版本的 Windows 操作系统?If you don't know, see Which version of Windows operating system am I running?. 下载文件后,运行该文件并按照安装向导中的步骤进行操作。After the file downloads, run it and follow the steps in the Setup Wizard.

  3. 在Microsoft 365中,以全局管理员或SharePoint管理员连接到SharePoint。Connect to SharePoint as a global admin or SharePoint admin in Microsoft 365. 若要了解具体操作步骤,请参阅 SharePoint 在线管理壳入门To learn how, see Getting started with SharePoint Online Management Shell.

    备注

    PowerShell 命令Request-SPOPersonalSite仅适用于允许登录的用户。The PowerShell command Request-SPOPersonalSite works only for users who are allowed to sign in. 如果已阻止用户登录,则可以通过使用在步骤 1 中创建的文本文件运行 PowerShell 命令 Set-MsolUser 来允许用户登录。If you've blocked users from signing in, you can allow them to sign in by running the PowerShell command Set-MsolUser using the text file you created in Step 1.

    Get-Content -path "C:\Users.txt" | ForEach-Object { Set-MsolUser -UserPrincipalName $_ -BlockCredential $False }
    
  4. 运行 PowerShell 命令 Request-SPOPersonalSite,使用之前在步骤 1 中创建的文本文件。Run the PowerShell command Request-SPOPersonalSite, consuming the text file you previously created in Step 1.

    $users = Get-Content -path "C:\Users.txt"
    Request-SPOPersonalSite -UserEmails $users
    

若要验证是否为用户创建了 OneDrive,请参阅获取组织中所有用户 OneDrive URL 的列表To verify that OneDrive has been created for your users, see Get a list of all user OneDrive URLs in your organization.

备注

如果为许多用户预预配 OneDrive,可能需要最多 24 小时才能创建 OneDrive 位置。If you are pre-provisioning OneDrive for many users, it might take up to 24 hours for the OneDrive locations to be created. 如果用户的 OneDrive 在 24 小时后未准备好,请联系支持人员。If a user's OneDrive isn't ready after 24 hours, please contact Support.

同时预设置多个用户Pre-provision many users at the same time

以下代码段将为大量用户预设置 OneDrive。The following code snippet will pre-provision OneDrive for a large number of users.

$Credential = Get-Credential
Connect-MsolService -Credential $Credential
Connect-SPOService -Credential $Credential -Url https://contoso-admin.sharepoint.com

$list = @()
#Counters
$i = 0


#Get licensed users
$users = Get-MsolUser -All | Where-Object { $_.islicensed -eq $true }
#total licensed users
$count = $users.count

foreach ($u in $users) {
    $i++
    Write-Host "$i/$count"

    $upn = $u.userprincipalname
    $list += $upn

    if ($i -eq 199) {
        #We reached the limit
        Request-SPOPersonalSite -UserEmails $list -NoWait
        Start-Sleep -Milliseconds 655
        $list = @()
        $i = 0
    }
}

if ($i -gt 0) {
    Request-SPOPersonalSite -UserEmails $list -NoWait
}

规划混合 OneDrivePlan hybrid OneDrive