Friday, September 4, 2015

My experience with O365 One Drive For Business and CreatePersonalSiteEnqueueBulk for Site Pre-Provisioning

If you want to pre provision one drive for business for every user in your organization, you need to implement a console application or a powershell script that will use SharePoint client object model in order to create users OneDrive for Business site collection.
In detail the method you need to use is CreatePersonalSiteEnqueueBulk of ProfileLoader class.

You need to pass to this method an array of string, each one will rapresent SharePoint online user's email.

Microsoft claims you can create a batch of max 200 users. Before execute another batch, you need to wait for previous batch completition (so you need to wait last user in batch one drive creation.)
No callback and no feedback are binded to this method. Simply ... wait.

In my experience, I've first tried with a 180 users batch but with no luck. Only first 8 users sites were created after 12 hours, while Microsoft claim max 5 minutes for user.

So my suggestion is to implement batch of only one user, call CreatePersonalSiteEnqueueBulk with this one item array, wait for one drive creation completition for that user and then execute next batch.

The method I've used to check one drive creation completition in c# is this simple snippet.

static bool OneDriveExistForUser(string userEmail, SharePointOnlineCredentials o365Cred)
    {
        bool retVal = false;
        string oneDriveURL = GetOneDriveUrlFromEmail(userEmail);
        HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(oneDriveURL);
        HttpWebResponse myHttpWebResponse;

        myHttpWebRequest.UseDefaultCredentials = true;
        myHttpWebRequest.Credentials = o365Cred;

        try
        {
   myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
            if ((myHttpWebResponse.StatusCode == HttpStatusCode.OK) || (myHttpWebResponse.StatusCode == HttpStatusCode.Forbidden))
            {
               retVal = true;
      myHttpWebResponse.Close();
            }
        }
        catch (WebException httpWE)
        {
            if ((((System.Net.HttpWebResponse)httpWE.Response).StatusCode == HttpStatusCode.OK) || (((System.Net.HttpWebResponse)httpWE.Response).StatusCode == HttpStatusCode.Forbidden))
            {
               retVal = true;
            }
        }

        return retVal;
    }


The two parameters passed to the method are user's email and Office365 Credentials (must be at least SharePoint Admin of the tenant).

Good luck!