共用方式為


為您組織中的使用者預先佈建 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 Online 管理命令介面

    注意事項

    如果您安裝的是舊版 SharePoint Online 管理命令介面,請移至 [新增或移除程式],並解除安裝 [SharePoint Online 管理命令介面]。

  3. 在 Microsoft 365 中以 SharePoint 系統管理員 身分連線到 SharePoint。 若要了解如何進行,請參閱開始使用 SharePoint Online 管理命令介面

    注意事項

    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 租用戶標識碼。 如需詳細資訊,請 參閱尋找標識符和功能變數名稱

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