How to pre-provision user sites in OneDrive for Business

By default, the first time that a user browses to their newsfeed, site, or a SkyDrive link, a OneDrive for Business site is automatically provisioned for them. In some cases, such as the following, you might want OneDrive for Business sites to be ready beforehand, or pre-provisioned:

  • Your organization has a custom process for adding new employees, and you want to create OneDrive for Business sites when you add new employees.

  • Your organization plans to migrate from on-premises to Office 365.

  • Your organization plans to migrate from another online storage service or repository.

This article describes how to pre-provision OneDrive for Business sites by using Windows PowerShell. You can also pre-provision OneDrive for Business sites by using the REST API or CSOM. For more information, see So you want to programmatically provision Personal Sites (OneDrive for Business) in Office 365 and the section titled "Use the ProfileLoader.CreatePersonalSiteEnqueueBulk method to provision personal sites and OneDrive for Business for multiple users (My Site Host administrators on SharePoint Online only)" in What’s new for developers in social and collaboration features in SharePoint 2013.

Before you begin

Before you begin this task, you'll need to do the following:

Pre-provision sites for users in OneDrive for Business

In this procedure for pre-provisioning OneDrive for Business sites for your Office 365 users, you will be doing the following:

  1. Create the PowerShell script to pre-provision OneDrive for Business sites from the provided code

  2. Create an input file that includes your users for which you want to pre-provision a OneDrive for Business site

  3. Run the PowerShell script

  1. Copy the following code, paste it into a text editor such as Notepad, save it, and name the file CreateOneDriveSites.ps1   :

    <#
    .SYNOPSIS
     This script adds an entry for each user specified in the input file 
     into the OneDrive provisioning queue
     
     
    .DESCRIPTION
     This script reads a text file with a line for each user. 
     Provide the User Principal Name of each user on a new line.
     An entry will be made in the OneDrive provisioning queue for each
     user up to 200 users.
    
    .EXAMPLE
    
     .\BulkEnqueueOneDriveSite.ps1 -SPOAdminUrl https://contoso-admin.sharepoint.com -InputfilePath C:\users.txt 
    
    .PARAMETER SPOAdminUrl
     The URL for the SharePoint Admin center
     https://contoso-admin.sharepoint.com
    
    .PARAMETER InputFilePath
     The path to the input file.
     The file must contain 1 to 200 users
     C:\users.txt
    
    .NOTES
     This script needs to be run by a SharePoint Online Tenant Administrator
     This script will prompt for the username and password of the Tenant Administrator
    #>
    
    param
    (
        #Must be SharePoint Administrator URL
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $SPOAdminUrl,
        
        [Parameter(Mandatory = $true)]
        [ValidateNotNullOrEmpty()]
        [string] $InputFilePath
    )
    
    Import-Module Microsoft.Online.SharePoint.PowerShell -ErrorAction SilentlyContinue -DisableNameChecking | Out-Null
    
    $module = Get-Module -Name Microsoft.Online.SharePoint.Powershell
    if ($null -eq $module)
    {
        Write-Host $("The Microsoft.Online.SharePoint.PowerShell Module could not be loaded.") -ForegroundColor Red
        Write-Host $("The module can be downloaded from: https://www.microsoft.com/en-us/download/details.aspx?id=35588") -ForegroundColor Red
        return
    }
    
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles") | Out-Null
    
    
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOAdminUrl)
    
    $Users = Get-Content -Path $InputFilePath
    
    if ($Users.Count -eq 0 -or $Users.Count -gt 200)
    {
        Write-Host $("Unexpected user count: [{0}]" -f $Users.Count) -ForegroundColor Red
        return 
    }
    
    $web = $ctx.Web
    Write-Host "Please enter a Tenant Admin username" -ForegroundColor Green
    $username = Read-Host
    
    Write-Host "Please enter your password" -ForegroundColor Green
    $password = Read-Host -AsSecureString
    
    $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password)
    $ctx.Load($web)
    $ctx.ExecuteQuery()
    
    $loader = [Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($ctx)
    $ctx.ExecuteQuery()
    
    $loader.CreatePersonalSiteEnqueueBulk($Users)
    $loader.Context.ExecuteQuery()
    
    
    Write-Host "Script Completed"
    

    Note: Notice that comments are included in the code to provide additional information.

  2. In a text editor such as Notepad, create a file that includes the Office 365 user accounts for which you want to provision OneDrive for Business sites. Each user account must be on a separate line.

    User Input file

    Save the file with the name UserInput.txt.

    Note: Each Input file is limited to 200 users. If you need to provision OneDrive for Business sites for more than 200 users, create multiple input files (for example, UserInput1.txt, UserInput2.txt, etc.).

  3. Open the SharePoint Online Management Shell.

  4. In the SharePoint Online Management Shell, change to the directory where you saved the CreateOneDriveSites.ps1    PowerShell script.

  5. At the command prompt, use following command:

    .\CreateOneDriveSites.ps1 -SPOAdminUrl <The URL for the SharePoint Admin center>  -InputfilePath <location of your UserInput file> 

    For example:

    .\CreateOneDriveSites.ps1 -SPOAdminUrl https://contoso-admin.sharepoint.com  -InputfilePath C:\UserInput1.txt 

    Running the script will prompt you for the Office 365 credentials, which you can enter.

    When the script is finished, the Windows PowerShell pane shows the status as Completed.

  6. If you have additional User Input files, rerun the script and change the -InputfilePath parameter to the other file.

See Also

What is OneDrive for Business?

Plan hybrid OneDrive for Business

Expand your Office skills
Explore training
Get new features first
Join Office Insiders

Was this information helpful?

Thank you for your feedback!

Thank you for your feedback! It sounds like it might be helpful to connect you to one of our Office support agents.

×