How to Create OneDrive for Business Site Collections using PowerShell?

Requirement: Pre-create OneDrive for Business Sites using PowerShell.

OneDrive for Business is Microsoft’s cloud-based storage solution that lets users store and work on files that are personal to them. It’s similar to a SharePoint Online document library with full control granted to users so that they can add, update, and delete files or folders in your OneDrive. OneDrive sites in Office 356 are typically created when they click on the OneDrive link for the first time. In my case, for a file share to SharePoint Online OneDrive migration project, I had to pre-create OneDrive for Business sites for N number of users. Let’s see how to create a personal site in SharePoint Online using PowerShell.

How to Create OneDrive Sites using PowerShell?

OneDrive for Business sites can be pre-created using the PowerShell cmdlet Request-SPOPersonalSite. Open SharePoint Online Management Shell, Connect as SharePoint Online Administrator by entering the appropriate credentials to the prompt and run this script to provision OneDrive for business sites using PowerShell.


#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL -credential $Cred

#sharepoint online create mysite powershell
Request-SPOPersonalSite -UserEmails "","" -NoWait $True

Wait for new Minutes, SharePoint Online timer job provisions My Sites for users given in the script. You can specify up to 200 Max. Please note, This cmdlet may fail if the account is disabled or the password is expired.  You can verify the created OneDrive sites using:

Get-SPOSite -Template "SPSPERS" -Limit ALL -includepersonalsite $True
onedrive for business create personal site

This lists all OneDrive site collections in your tenant.

OneDrive vs OneDrive for Business:

  • OneDrive is your personal online storage, which you can get with Microsoft accounts (E.g. with an initial 15 GB of disk space. You can use your personal OneDrive to store documents, photos, videos, etc. in the cloud and share them with your friends and family. You can use the OneDrive client to sync your files and easily access them anywhere from Windows, Mac, and mobile devices.
  • OneDrive for Business: OneDrive for business sites are intended for business and offered through your work account by Office 365 to store, share, and sync all work files. You get 1 TB of storage for individual use, typically. Your account settings such as external sharing, storage, and access are managed by your organization. You can install the OneDrive for Business client to sync your files to your devices. 

OneDrive for Business: Create Personal Site

We can also create new OneDrive sites for existing users using PowerShell CSOM. Here is how to create a personal site in SharePoint Online with PowerShell.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

#Set parameter values

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = $Credentials

    #Get Profile Loader Object

    #Create onedrive for business sites

    Write-host -f Green "OneDrive for Business Sites Creation Successfully Queued!"
Catch {
        write-host -f Red "Error Creating OneDrive for Business Sites!" $_.Exception.Message

Now we started the migration project from file shares to OneDrive so that users get many new features such as version history, metadata, recycle bin, permissions, check-in/check-out, auditing, web interface, etc. Let’s see how to create a personal site in SharePoint Online using PnP PowerShell.

Pre-Create OneDrive for Business Sites using PnP PowerShell

OneDrive for Business sites gets created when the user tries to log in to the site for the first time. There are situations where users never logged in, and therefore no OneDrive sites were created! We had to migrate the data to the user’s personal site from a network file share.

So, How to create a personal site or OneDrive for Business site for the user? Well, with this PnP PowerShell script, you can create the OneDrive for Business sites! Either one user at a time or multiple users!

#Config Variables
$TenantSiteURL =  ""

#Connect to PnP Online
Connect-PnPOnline -Url $TenantSiteURL -Interactive

#Create OneDrive for User
New-PnPPersonalSite -Email ""

#Pre-Provision OneDrive for Business Site for Multiple users
New-PnPPersonalSite -Email "", ""

It is worth mentioning that this cmdlet takes a moment to provision OneDrive for business sites.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *