How To Pre-Provision A User’s OneDrive For Business In PowerShell

When a user is licensed for OneDrive for Business, this does not create the backend SharePoint site for them.  Instead One Drive is provisioned on the first use.  This makes a lot of sense as not all users will use OneDrive, and an automatic setup would leave a lot of empty sites around.

In other articles, we have explored how to report on users that have a OneDrive, as well as their sharing policies, here:  https://madmike.net/how-to-view-one-drive-for-business-sharing-polices-in-powershell-the-admin-center/

In an Office 365 Tenant-To-Tenant migration, we must write to the user’s target OneDrive and don’t typically want to wait for their first use.  There could be other situations where someone may want to pre-provision users to support some applications.

If you go into the admin center, and you look at a user that is licensed, but is not provisioned, you will see this:

Information: OneDrive isn’t set up for this user. Ask the person to go to portal.office.com/onedrive to set it up. It might take a while. If you still see this message 24 hours later, contact Support.

If you are doing a Tenant-To-Tenant Migration, you may need to pre-provision OneDrive for users being migrated.  This used to involve some trickery, but Microsoft has thankfully created a command called request-spopersonalsite for this purpose.  This command was even built with bulk use in mind, something well appreciated!  More information on the command can be found here:  https://docs.microsoft.com/en-us/onedrive/pre-provision-accounts

How To Pre-Provision A User’s OneDrive For Business In PowerShell

We will use the request-spopersonalsite PowerShell command to achieve this.

  1. In order to do this, you will need to have installed the SharePoint Online Management Shell found here: https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online?view=sharepoint-ps
  2. Open the SharePoint Online Management Shell
  3. Your SharePoint online admin URL is your orgname-admin.sharepoint.com  For example, if my tenant name was madmike / madmike.onmicrosoft.com, then my SharePoint URL is https://madmike-admin.sharepoint.com.
  4. You can either execute the below script line-by-line or save it as a .ps1 file.  Please make the following changes for it to work in your environment
    • Change the $AdminURL to your SPO Admin URL
    • Create a .txt file with a list of all the users that will need to be pre-provisioned.  Just enter them one per line and save this file, no separator needed.  Update the path to this file in $NewODFBUsers parameter below.
$AdminUrl = "https://miwetest-admin.sharepoint.com"
Connect-SPOService -Url $AdminUrl
$NewODFBUsers = Get-Content -path "C:\Path\NewODFBUsers.txt"
Request-SPOPersonalSite -UserEmails $NewODFBusers
#Tested Apr 26 2020
  • Note: After importing the list, if you want to check it, you can simply type $NewODFBUsers and the console will list all the users stored in the parameter.
  • Second Note: Depending upon the load on the Office 365 service, this can take up to 24 hours to provision.  This process has been known to have a few outages over the years, so you can also check the service status to see if there are any active issues.  You can also do this process on a Sunday morning, and from my experience, it will fly right through in minutes!
  • One provisioned, you will see a box like the one below, and be able to change the user’s policy and settings.

2 comments on “How To Pre-Provision A User’s OneDrive For Business In PowerShell

  1. Thanks Mike!

    It is worth noting that the user must have a suitable licence and can’t be blocked for sign in, or the odfb will not provision.

    Cheers
    Twan

Comments are closed.