Provisioning OneDrive for Business in advance for new AzureAD users

To save a new OneDrive user time, or if we want to migrate content into a setup of new OneDrives as part of say a migration project, we can pre-provision OneDrives.

There are some hit and miss blogs out there, partly due to the fact that nothing stays still, and some code that worked six months ago might have stopped working, perhaps because an SDK has been updated.

A great demonstration of working script this blog entry Office 365 Mass Provision PersonalSite/OneDrive

The strategy of this script is to:

  1. connect to your AzureAD to get a list of licensed users
  2. if there is an error getting the users mysite (OneDrive for Business) then add them to a list
  3. provision the folks in the list

I found that in the Azure Connection script, it was trivial to use Azure AD extended attributes to filter, by say Department.

So where we have:
$filter = 'accountEnabled eq true';
$licenseduserList = Get-AzureADUser -All $True -Filter $filter | Where { ($.AssignedLicenses -ne $Null -and $.AssignedLicenses.Count -gt 0) -and !($.UserPrincipalName -like "8*" -or $.UserPrincipalName -like "9*")} | Sort-Object UserPrincipalName

We might add to the filter:
$filter = "accountEnabled eq true and starts with(department,'Human Resources')"';

This script has a fair few pre-requisites, which is why that "if your life depends" upon such as process I would consider adopting a robust managed code solution. Why?

  1. PowerShell scripts with MS SDKS can be "brittle"
  2. Exception handling / logging / all the cross cutting concerns guff
  3. Managed code written in say C# can work with any sort of container such as timerjob / workflow / FLOW etc.
  4. "divide and conquer" the task to boost speed, although you will always have the bottleneck on the connection to Microsoft and your location