Home About Tools Projects Guides & Blog ⚡ Hire Me ✦ Websites Contact →
☁️ M365 Admin

How to Pre-Provision OneDrive Using PowerShell

In Microsoft 365, OneDrive sites aren't created the moment you add a user. They're provisioned lazily, nothing actually gets created until a user signs in for the first time. Most of the time that's fine, but it becomes a real problem when you're running a migration, deploying Intune Known Folder Move, or building automated workflows that need to write to a OneDrive URL that doesn't exist yet.

Pre-provisioning solves this. The two scripts below use the SharePoint Online Management Shell to trigger site creation for all your users at once, or just a single user, before anyone has touched their account.

Prerequisites

🔑
Admin Role
Global Administrator or SharePoint Administrator role required in your M365 tenant.
📦
PowerShell Modules
SharePoint Online Management Shell and Microsoft Graph PowerShell modules, install commands below.

Open PowerShell as Administrator and run the following to install or update the required modules:

PowerShell
# Install / update the required modules
Install-Module -Name Microsoft.Online.SharePoint.PowerShell -Force -AllowClobber
Install-Module -Name Microsoft.Graph -Force -AllowClobber

Scenario 1, Provision OneDrive for All Users

1
Bulk Provisioning, All Users
Provision-AllOneDrives.ps1

Use this script for initial tenant setups, pre-migration preparation, or any time you want to make sure every existing licensed user has a OneDrive site ready before they sign in.

📦 Tenant setup 🔄 Pre-migration 💻 Intune KFM deployment 🏢 Bulk onboarding
PowerShell, Provision-AllOneDrives.ps1
# ── Pre-Provision OneDrive for ALL Users ────────────────────────
# Connects to SharePoint Online and Microsoft Graph, retrieves all
# licensed users, and triggers OneDrive site creation for each one.
# Run as Global Admin or SharePoint Admin.
# ─────────────────────────────────────────────────────────────────

# Prompt for your SharePoint Admin Center URL
$AdminUrl = Read-Host "Enter your SharePoint Admin URL (e.g. https://contoso-admin.sharepoint.com)"

# Connect to SharePoint Online
Write-Host "Connecting to SharePoint Online..." -ForegroundColor Cyan
Connect-SPOService -Url $AdminUrl

# Connect to Microsoft Graph to retrieve users
Write-Host "Connecting to Microsoft Graph..." -ForegroundColor Cyan
Connect-MgGraph -Scopes "User.Read.All"

# Get all users with a UsageLocation set (licensed users)
Write-Host "Retrieving licensed users..." -ForegroundColor Cyan
$Users = Get-MgUser -All -Filter "assignedLicenses/`$count ne 0" -ConsistencyLevel eventual -CountVariable userCount

Write-Host "Found $($Users.Count) licensed user(s). Starting provisioning..." -ForegroundColor Green

# Build array of UPNs and request OneDrive provisioning in batches of 200
$BatchSize = 200
$Upns      = $Users.UserPrincipalName

for ($i = 0; $i -lt $Upns.Count; $i += $BatchSize) {
    $Batch = $Upns[$i..(-join ($i + $BatchSize - 1))]
    Write-Host "Provisioning batch starting at index $i ($($Batch.Count) users)..."
    Request-SPOPersonalSite -UserEmails $Batch -NoWait
}

Write-Host "Done! OneDrive provisioning requests submitted for all $($Users.Count) users." -ForegroundColor Green
Write-Host "Sites will appear in the SharePoint Admin Centre within a few minutes." -ForegroundColor Yellow

How to run it

  • 1Save the script, paste into VS Code or Notepad and save as Provision-AllOneDrives.ps1 somewhere easy to find, e.g. C:\Scripts\.
  • 2Open PowerShell as Administrator and go to the folder: cd C:\Scripts
  • 3Run the script: .\Provision-AllOneDrives.ps1
  • 4Enter the URL when prompted, your SharePoint Admin Center URL, e.g. https://contoso-admin.sharepoint.com
  • 5Sign in twice, browser windows will appear for SharePoint Online and Microsoft Graph authentication. Use your admin account for both.
  • 6Monitor the output, the script reports how many users it found and logs progress as it batches through them.
Provisioning is asynchronous
The Request-SPOPersonalSite cmdlet submits the request and returns immediately, it doesn't wait for each site to be created. Sites will appear in the SharePoint Admin Centre within a few minutes. Running the script against already-provisioned users is safe, it won't duplicate or overwrite anything.

Scenario 2, Provision OneDrive for a Single User

2
Single User Provisioning
Provision-SingleOneDrive.ps1

Use this for onboarding a specific new employee, fixing a provisioning issue for one account, or testing the process before running the bulk script.

👤 Single onboarding 🔧 Fix provisioning issue 🧪 Testing
PowerShell, Provision-SingleOneDrive.ps1
# ── Pre-Provision OneDrive for a Single User ────────────────────
# Usage: .\Provision-SingleOneDrive.ps1 -UserPrincipalName "user@domain.com"
# ─────────────────────────────────────────────────────────────────
param(
    [Parameter(Mandatory = $true)]
    [string]$UserPrincipalName
)

# Prompt for SharePoint Admin Center URL
$AdminUrl = Read-Host "Enter your SharePoint Admin URL (e.g. https://contoso-admin.sharepoint.com)"

# Connect to SharePoint Online
Write-Host "Connecting to SharePoint Online..." -ForegroundColor Cyan
Connect-SPOService -Url $AdminUrl

# Validate the user exists before attempting provisioning
try {
    $User = Get-SPOUser -Site $AdminUrl -LoginName $UserPrincipalName -ErrorAction Stop
    Write-Host "User found: $($User.DisplayName)" -ForegroundColor Green
} catch {
    Write-Warning "Could not find user '$UserPrincipalName' in SharePoint. Proceeding anyway..."
}

# Request OneDrive provisioning for the single user
Write-Host "Requesting OneDrive provisioning for: $UserPrincipalName" -ForegroundColor Cyan
Request-SPOPersonalSite -UserEmails $UserPrincipalName -NoWait

Write-Host "Done! OneDrive provisioning requested for $UserPrincipalName." -ForegroundColor Green
Write-Host "The site will be available within a few minutes." -ForegroundColor Yellow

How to run it

  • 1Save the script as Provision-SingleOneDrive.ps1 in C:\Scripts\.
  • 2Open PowerShell as Administrator and work through: cd C:\Scripts
  • 3Run with the -UserPrincipalName parameter, passing the user's email address:
PowerShell
# Replace the email with the target user's UPN
.\Provision-SingleOneDrive.ps1 -UserPrincipalName "john.smith@contoso.com"
  • 4Enter the SharePoint Admin URL when prompted, then sign in to the browser window that appears.
  • 5The script confirms the user and submits the provisioning request. Check the SharePoint Admin Centre in a few minutes to confirm the site has been created.

Troubleshooting

"Unsupported browser" error on Connect-SPOService

This is one of the most common errors when connecting to SharePoint Online via PowerShell. The built-in browser component used by Connect-SPOService doesn't meet modern authentication requirements on some systems.

Fix: Add the -UseWebLogin parameter to force authentication through your default external browser instead:

PowerShell
# Replace the standard Connect-SPOService call with this
Connect-SPOService -Url "https://yourdomain-admin.sharepoint.com" -UseWebLogin
ℹ️
Other common issues
Module not found: Re-run the Install-Module commands from the Prerequisites section in an elevated PowerShell window.

Insufficient permissions: Make sure the account you're authenticating with has Global Admin or SharePoint Admin role, not just a regular user with admin rights to a single site.

Sites not appearing after script: Provisioning is async. Wait 5–10 minutes and refresh the SharePoint Admin Centre. Large tenants with hundreds of users can take longer.
// monthly tips

Get M365 tips in your inbox

Practical Intune and Microsoft 365 tips, once a month. No spam, no fluff.