为组织内的用户预设置 OneDrive

默认情况下,用户首次浏览到其 OneDrive 时,系统会自动创建 (为其预配) 。 在某些情况下,例如以下情况,你可能希望用户的 OneDrive 位置事先准备就绪或预先预配:

  • 你的组织有一个用于添加新员工的自定义流程,你希望在添加新员工时创建 OneDrive。

  • 你的组织计划从本地 SharePoint Server 迁移到 Microsoft 365。

  • 你的组织计划从另一个联机存储服务迁移。

本文介绍如何使用 PowerShell 为用户预预配 OneDrive。

重要

必须允许预先预配的用户帐户登录,并且还必须分配 SharePoint 许可证。 若要使用此 cmdlet 预配 OneDrive,你必须是 SharePoint 管理员,并且必须分配有 SharePoint 许可证。

注意

如果要为大量用户预预配 OneDrive,可能需要几天时间才能创建 OneDrive 位置。

为用户预预配 OneDrive

  1. 如果要为许多用户预预配 OneDrive,请创建这些用户的列表并将其另存为文件。 例如,创建一个名为 Users.txt 的文本文件,其中包含:

    user1@contoso.com
    user2@contoso.com
    user3@contoso.com
    
  2. 下载最新的SharePoint在线管理壳

    注意

    如果你已安装早期版本的SharePoint Online Management Shell,请进入添加或删除程序并卸载 "SharePoint Online Management Shell"。

  3. 以 Microsoft 365 中的 SharePoint 管理员身份连接到 SharePoint 。 若要了解具体操作步骤,请参阅 SharePoint 在线管理壳入门

    注意

    PowerShell 命令 Request-SPOPersonalSite 仅适用于允许登录的用户。 如果已阻止用户登录,则可以使用在步骤 1 中创建的文本文件运行 PowerShell 命令 Update-MgUser 来允许他们登录。

    Get-Content -path "C:\Users.txt" | ForEach-Object { Update-MgUser -UserPrincipalName $_ -BlockCredential $False }
    
  4. 运行 PowerShell 命令 Request-SPOPersonalSite,使用之前在步骤 1 中创建的文本文件。

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

若要验证是否已为用户创建 OneDrive,请参阅 获取组织中所有用户 OneDrive URL 的列表

为组织中的所有许可用户预预配 OneDrive

以下代码片段以 199 个批次预预配 OneDrive。

注意

需要提供Microsoft 365 租户 ID。 有关详细信息,请参阅 查找 ID 和域名

Param(
    [Parameter(Mandatory = $True)]
    [String]
    $SharepointURL,
    [Parameter(Mandatory = $True)]
    [String]
    $tenantID
)

$scope = 'User.Read.All'
Connect-MgGraph -TenantId $tenantId -Scopes $scope
Connect-SPOService -Url $SharepointURL;

$list = @() #list of UPN to pass to the SP command
$Totalusers = 0 #total user provisioned.

#Get licensed users
$users = Get-MgUser -Filter 'assignedLicenses/$count ne 0' -ConsistencyLevel eventual -CountVariable licensedUserCount -All -Select UserPrincipalName

foreach ($u in $users) {
    $Totalusers++
    Write-Host "$Totalusers/$($users.Count)"
    $list += $u.userprincipalname

    if ($list.Count -eq 199) {
        #We reached the limit
        Write-Host "Batch limit reached, requesting provision for the current batch"
        Request-SPOPersonalSite -UserEmails $list -NoWait
        Start-Sleep -Milliseconds 655
        $list = @()
    }
}

if ($list.Count -gt 0) {
    Request-SPOPersonalSite -UserEmails $list -NoWait
}
Disconnect-SPOService
Disconnect-MgGraph
Write-Host "Completed OneDrive Provisioning for $Totalusers users"

规划混合 OneDrive