Auto provision OneDrive for users – programmatically

By default OneDrive storage is not provisions for users until they click on the OneDrive link at the top navigation bar in Office 365.

This can be a massive pain, especially if they’re using the iPad app which wont provision OneDrive instead it just repeatedly asks them to login! Ouch!

Fortunately there is a way to do this using CSOM. Firstly download the client runtime dlls from ​

After installing, add the version 16 DLLs to a new c# console application in Visual Studio 2013 references from Program files/SharePoint Client Components.

Add the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.UserProfiles;

namespace CreatePersonalSiteBulkConsole
class Program
static void Main(string[] args)
string userName = “”;
string passwordStr = “password”;
string serverUrl = “”;

using (var clientContext = new ClientContext(serverUrl))
SecureString password = new SecureString();
Array.ForEach(passwordStr.ToCharArray(), c => password.AppendChar(c));

var credentials = new SharePointOnlineCredentials(userName, password);

clientContext.Credentials = credentials;

var web = clientContext.Web;
ProfileLoader loader = ProfileLoader.GetProfileLoader(clientContext);

if (loader == null)
throw new InvalidOperationException(“Failed to get ProfileLoader”);

string[] userEmails = { “”, “” };