{"id":1071,"date":"2016-09-06T16:54:51","date_gmt":"2016-09-06T15:54:51","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=1071"},"modified":"2016-09-06T16:54:51","modified_gmt":"2016-09-06T15:54:51","slug":"pre-populating-onedrive-containers-in-an-education-tenancy","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/","title":{"rendered":"Pre-populating OneDrive containers in an Education tenancy"},"content":{"rendered":"<p>Looks like I\u2019ve been neglecting the blog a bit over the last few months, mainly due to being very busy a long migration project that has taken a lot of my time up. That said it has given me a lot of material to think about and potentially blog about too! The first aspect that I wanted to highlight was the differences between a standard E1\/3\/5 tenant compared to the equivalent Education tenant when it comes to SharePoint Profiles and by their symbiotic relationship, OneDrive containers.<\/p>\n<p>Whenever I have worked on a large Office 365 implementation, we\u2019ve always tried to pre-populate the OneDrive containers so that on launch day, we don\u2019t have a large amount of people waiting for their OneDrives to provision. (In case you weren\u2019t aware, the OneDrive container only gets provisioned when either a user clicks on the OneDrive link, or the profile is forced through code)<\/p>\n<p>The way we\u2019ve always approached this in the past is to let the AAD Sync process run to provision all of the users into Office 265\/Azure AD then allow the SharePoint import wizard time to import the users and create profiles for them. We then have a PowerShell script that runs through the active profiles and checks the status of their personal site instantiation property. This shows whether the user is <strong><em>Unitialized<\/em><\/strong> (No site),<strong><em> Enqueued<\/em><\/strong> (awaiting creation), <strong><em>Created<\/em><\/strong> and a number of other useful states. (See here for the TechNet summary.) Our script then adds the unitialized users to a list for creation and these are added to the queue 100 users at a time (There\u2019s a 200 user limit to the queue).<\/p>\n<p>However in an Education tenancy, SharePoint only creates a profile for the user when they actually logon to SharePoint or OneDrive<\/p>\n<p>The problem that we hit with the Education tenancy lies in the way that the SharePoint User Profile Sync works, which is different to the standard E subscriptions. Instead of importing users as they are added to Azure AD, SharePoint only creates a profile for the user when they actually logon to SharePoint or OneDrive. I\u2019m assuming that this is to reduce the load on Microsoft&#8217;s own servers as education tenancies by their very nature generally have a lot of users in them.<\/p>\n<p>With this in mind you can see that the usual approach of walking the User Profile store to find those users that don\u2019t have a personal site instantiated isn\u2019t going to work, but after a bit of digging I came across the ProfileLoader object which also contains the CreatePersonalSiteEnqueueBulk() method that we use in the other script. This particular object doesn\u2019t need an active profile to begin with, and the act of queuing the user for personal site creation forces the creation of their profile and the subsequent OneDrive container. (On a side note, I did try using SPWeb.EnsureUser() to add a user to a site which it does, but this does NOT trigger the profile creation!)<\/p>\n<p>Here\u2019s the basic steps you need to connect to your Admin site and create a single user, I\u2019ll leave it to you to adapt the script as you need.<\/p>\n<p>Paul.<\/p>\n<hr \/>\n<p>&nbsp;<\/p>\n<pre># Specifies the URL for your organization's SPO admin service\r\n$AdminURI = \"https:\/\/tenantname-admin.sharepoint.com\"\r\n\r\n# Specifies the User account for an Office 365 global admin in your organization\r\n$AdminAccount = \"paul.hunt@tenantname.onmicrosoft.com\"\r\nif(!$AdminCredentials)\r\n{\r\n    $AdminCredentials = get-credential -UserName $adminAccount -Message \"Input password for $AdminAccount\"\r\n}\r\n\r\n# You'll need the Client DLLs (I put mine in the same location as the scripts)\r\n\r\nAdd-type -path .\\Microsoft.SharePoint.Client.dll\r\nAdd-type -path .\\Microsoft.SharePoint.Client.Runtime.dll\r\nadd-type -path .\\Microsoft.SharePoint.Client.UserProfiles.dll\r\n\r\n#Create a credentials object for SPO.\r\n$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($AdminCredentials.UserName,$AdminCredentials.Password)\r\n\r\n\r\n# Add the path of the User Profile Service to the SPO admin URL, then create a new webservice proxy to access it\r\n$proxyaddr = \"$AdminURI\/_vti_bin\/UserProfileService.asmx?wsdl\"\r\n$UserProfileService= New-WebServiceProxy -Uri $proxyaddr -UseDefaultCredential False\r\n$UserProfileService.Credentials = $spoCredentials\r\n\r\n# Set variables for authentication cookies\r\n$strAuthCookie = $spoCredentials.GetAuthenticationCookie($AdminURI)\r\n$uri = New-Object System.Uri($AdminURI)\r\n$container = New-Object System.Net.CookieContainer\r\n$container.SetCookies($uri, $strAuthCookie)\r\n$UserProfileService.CookieContainer = $container\r\n\r\n$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURI)\r\n$ctx.Credentials = $spoCredentials\r\n\r\n$profileLoader = [Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($ctx)\r\n\r\n#With the profile loader in place we can request a user provisioning.\r\n#Where username@upn is the User Principal Name of the user you want to add.\r\n#This can be a string array with multiple UPNs to process.\r\n\r\n$profileLoader.CreatePersonalSiteEnqueueBulk(\"username@upn\")\r\n$ctx.ExecuteQuery()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Looks like I\u2019ve been neglecting the blog a bit over the last few months, mainly due to being very busy a long migration project that has taken a lot of my time up. That said it has given me a lot of material to think about and potentially blog about too! The first aspect that &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[215,51,152,110,139],"tags":[154,216],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Pre-populating OneDrive containers in an Education tenancy - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pre-populating OneDrive containers in an Education tenancy - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"Looks like I\u2019ve been neglecting the blog a bit over the last few months, mainly due to being very busy a long migration project that has taken a lot of my time up. That said it has given me a lot of material to think about and potentially blog about too! The first aspect that &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2016-09-06T15:54:51+00:00\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/\",\"name\":\"Pre-populating OneDrive containers in an Education tenancy - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"datePublished\":\"2016-09-06T15:54:51+00:00\",\"dateModified\":\"2016-09-06T15:54:51+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pre-populating OneDrive containers in an Education tenancy - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/","og_locale":"en_US","og_type":"article","og_title":"Pre-populating OneDrive containers in an Education tenancy - Blog of an overweight SharePoint addict","og_description":"Looks like I\u2019ve been neglecting the blog a bit over the last few months, mainly due to being very busy a long migration project that has taken a lot of my time up. That said it has given me a lot of material to think about and potentially blog about too! The first aspect that &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2016-09-06T15:54:51+00:00","author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/","name":"Pre-populating OneDrive containers in an Education tenancy - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"datePublished":"2016-09-06T15:54:51+00:00","dateModified":"2016-09-06T15:54:51+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2016\/09\/pre-populating-onedrive-containers-in-an-education-tenancy\/"]}]},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1071"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=1071"}],"version-history":[{"count":4,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1071\/revisions"}],"predecessor-version":[{"id":1076,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/1071\/revisions\/1076"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=1071"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=1071"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=1071"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}