Pre-provision OneDrive in Advance for Your Organization’s Users Before Doing Migration

Pre-provision OneDrive means creating the OneDrive location for users before they actually access it. This can be useful in scenarios such as adding new employees or migrating from another storage service. PowerShell can be used to automate the process of creating OneDrive accounts for multiple users at once.

OneDrive migration

Pre-provision OneDrive for users

  • If you’re pre-provisioning OneDrive for many users, create a list of these users and save it as a file. For example, create a text file named Users.txt that contains:
[email protected]
[email protected]
[email protected]
$users = Get-Content -path "C:\Users.txt"
Request-SPOPersonalSite -UserEmails $users

Setting up OneDrive for all licensed users in your organization

The following code snippet will pre-provision OneDrive in batches of 199

$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
}

If you’re in need of an experienced and reliable IT consultant, don’t hesitate to contact me.