Provisioning OneDrive for Microsoft365 Users Before First Login

Why Pre-Provision OneDrive?
By default, OneDrive accounts for Microsoft 365 users are not created until they sign in for the first time. However, if you’re planning a migration from another cloud provider, such as Google Drive, you need to provision these OneDrive accounts in advance to ensure a smooth transition as we found out.
Below is a rough guide and SharePoint PowerShell script to automate the process.
Pre-Requisites
Before running the script, you need to ensure that PowerShell allows execution of scripts. Run the following command in PowerShell (this cannot be part of the script itself):
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Unrestricted
This enables execution for the session without changing system-wide policies.
The PowerShell Script
Save the following script as provision_onedrive.ps1
. It connects to your SharePoint Online admin centre and checks whether OneDrive is provisioned for each user. If not, it requests its creation.
# Define the list of user emails
$UserEmails = @(
"[email protected]",
"[email protected]",
"[email protected]"
)
# Define SharePoint Online Admin URL (replace with your actual tenant)
$TenantAdminURL = "https://[your-tenant]-admin.sharepoint.com"
# Connect to SharePoint Online (if not already connected)
Try {
Connect-SPOService -Url $TenantAdminURL -ErrorAction Stop
Write-Host "Connected to SharePoint Online successfully."
} Catch {
Write-Host "Error connecting to SharePoint Online: $_" -ForegroundColor Red
Exit
}
# Loop through each user email
foreach ($email in $UserEmails) {
Write-Host "Checking OneDrive status for $email..."
# Check if OneDrive is already provisioned
$site = Get-SPOSite -IncludePersonalSite $true -Limit all | Where-Object { $_.Owner -eq $email } -ErrorAction SilentlyContinue
if ($site) {
Write-Host "OneDrive already exists for $email" -ForegroundColor Green
} else {
Write-Host "Provisioning OneDrive for $email..." -ForegroundColor Yellow
Request-SPOPersonalSite -UserEmails $email
Write-Host "OneDrive provisioning requested for $email" -ForegroundColor Cyan
}
}
Write-Host "OneDrive provisioning script completed." -ForegroundColor Magenta
How It Works
- The script defines a list of user emails.
- It connects to the SharePoint Online admin centre.
- It checks if OneDrive is already provisioned for each user.
- If OneDrive is missing, it requests its creation.
Running the Script
To execute the script, open PowerShell as an administrator and run:
.\provision_onedrive.ps1
You'll see output indicating whether each user's OneDrive already exists or has been requested for provisioning.
Final Thoughts
Pre-provisioning OneDrive ensures a seamless migration for users switching from Google Drive or other storage solutions. This automation removes delays and guarantees that user drives are ready before they even log in.
Let me know in the comments if you have any questions or if you’d like additional automation enhancements!