{"id":365,"date":"2015-08-07T10:36:47","date_gmt":"2015-08-07T10:36:47","guid":{"rendered":"https:\/\/www.lieben.nu\/liebensraum\/?p=365"},"modified":"2015-08-07T10:36:47","modified_gmt":"2015-08-07T10:36:47","slug":"provisioning-onedrive-for-business-for-all-your-users","status":"publish","type":"post","link":"https:\/\/lieben.nu\/liebensraum\/2015\/08\/provisioning-onedrive-for-business-for-all-your-users\/","title":{"rendered":"Provisioning Onedrive for Business for all your users"},"content":{"rendered":"<p>Since the inception of the <a href=\"https:\/\/www.lieben.nu\/liebensraum\/onedrivemapper\/\">OneDriveMapper <\/a>script, I&#8217;ve often been asked if there is a way to pre-provision Onedrive for Business storage for users.<\/p>\n<p>When a user signs into Office 365 for the first time and clicks Onedrive, their Onedrive for Business storage will be allocated and initialized, before that, it is not possible to map their OneDrive storage, or sometimes more importantly: to migrate data to it.<\/p>\n<p>As a good consultant or IT admin, you don&#8217;t want to force your users to do this before they can map their drive or before you migrate their data because you like to automate things, repetitive or manual process tend to be unreliable.<\/p>\n<p>Doing this the smart way, is <!--more-->scripting it. <strong>Of course your users already have to have a license.<\/strong><\/p>\n<p>Don&#8217;t forget to <a href=\"https:\/\/www.lieben.nu\/liebensraum\/2015\/08\/setting-administrative-permissions-on-all-your-onedrive-for-business-accounts\/\">set administrative permissions on all accounts<\/a>\u00a0afterwards, if you intend to migrate data there for your users.<\/p>\n<p>The following script will pre-provision OneDrive for ALL users in your Office 365 environment.<\/p>\n<p><a href=\"https:\/\/www.lieben.nu\/liebensraum\/wp-content\/uploads\/2015\/08\/ODFB_BP_v0.2.zip\">ODFB_BP_v0.2<\/a><\/p>\n<p>Source:<\/p>\n<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n\n########\n#ODFB Bulk Provisioning\n#Copyright: Free to use, please leave this header intact\n#Author: Jos Lieben (OGD)\n#Company: OGD (http:\/\/www.ogd.nl)\n#Script help: http:\/\/www.lieben.nu\n#Purpose: Provision Onedrive for all users in Office 365\n########\n#Changes:\n#V0.2 fixed a bug, .Clear() does not function as expected in Powershell, = @() does.\n#V0.21 changed the default batch size to 10, this seems to work better (reported by Iain)\n########\n#Requirements:\n########\n&lt;#MS Online Services Signin Assistant:\nhttps:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=41950\nAzure AD Module (x64):\nhttp:\/\/social.technet.microsoft.com\/wiki\/contents\/articles\/28552.microsoft-azure-active-directory-powershell-module-version-release-history.aspx\nPowershell 4\n.NET 4.5\nSharepoint Server 2013 Client Components\nhttps:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=42038\nrun \u201cSet-Executionpolicy Unrestricted\u201d in an elevated powershell window\nWindows 7+ or Windows Server 2008+\n#&gt;\n\n$o365login = &quot;admin@ogdemo1.onmicrosoft.com&quot; #Username of O365 Admin\n$o365pw = &quot;YourPassword&quot; #Password of O365 Admin\n$logfile = ($env:APPDATA + &quot;\\ODFB_BP.log&quot;) #Logfile in case of errors\n$spURL = &quot;https:\/\/ogdemo1-admin.sharepoint.com&quot; #URL to your SP Admin site $batch_size = 10 #Maximum accounts to provision at once, technet lists 200 as the max, but users have reported 10 is optimal \n\n#Start script\nac $logfile &quot;-----$(Get-Date) ODFB_BP v0.2 $($env:COMPUTERNAME) Session log-----`n&quot;\n\n#build Credential Object\n$secpasswd = ConvertTo-SecureString $o365pw -AsPlainText -Force\n$Credentials = New-Object System.Management.Automation.PSCredential ($o365login, $secpasswd)\n\n#Load sharepoint module\ntry{\n &#x5B;System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SharePoint.Client&quot;) | Out-Null &#x5B;System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SharePoint.Client.Runtime&quot;) | Out-Null &#x5B;System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SharePoint.Client.UserProfiles&quot;) | Out-Null\n}catch{\n $errorstring = &quot;ERROR: Failed to load Sharepoint Libraries, exiting&quot;\n ac $logfile $errorstring\n Write-Host $errorstring\n Pause\n Exit\n}\n#load Azure module\n$env:PSModulePath += &quot;;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\Modules\\&quot;\ntry{\n Import-Module msonline\n}catch{\n $errorstring = &quot;ERROR: Failed to load Azure module, exiting&quot;\n ac $logfile $errorstring\n ac $logfile $error&#x5B;0]\n Write-Host $errorstring\n Pause\n Exit\n}\n#connect to MSOL\ntry{\n Connect-MsolService -Credential $Credentials\n}catch{\n $errorstring = &quot;Critical error, unable to connect to O365, check the credentials&quot;\n ac $logfile $errorstring\n ac $logfile $error&#x5B;0]\n Write-Host $errorstring\n Pause\n Exit\n}\n\n#fetch all UPN's\n$users = Get-MsolUser -All | Select-Object UserPrincipalName\n\n#Build sP object\n$client = New-Object Microsoft.SharePoint.Client.ClientContext($spURL) $clientweb = $client.Web $client.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($o365login,$secpasswd) #Connect $client.Load($clientweb) try{ $client.ExecuteQuery() }catch{ $errorstring = &quot;Critical error, unable to connect to Sharepoint Online, check admin url and credentials&quot;\n ac $logfile $errorstring\n ac $logfile $error&#x5B;0]\n Write-Host $errorstring $error&#x5B;0]\n Pause\n Exit } $loader =&#x5B;Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($client) $profile = $loader.GetUserProfile() $client.Load($profile) $client.ExecuteQuery() #enqueue per batch_size users (max is 200 users per batch) $total = $users.Count $batchjob = @() for($i = 0; $i -lt $total; $i++){ $batchjob += $users&#x5B;$i].UserPrincipalName if($i+1 -eq $total -or $batchjob.Count -gt $batch_size){ #enqueue in loader try{ $loader.CreatePersonalSiteEnqueueBulk($batchjob) $loader.Context.ExecuteQuery() }catch{ $errorstring = &quot;Critical error, unable to create bulk provisioning job in Sharepoint Online&quot;\n ac $logfile $errorstring\n ac $logfile $error&#x5B;0]\n ac $logfile $batchjob\n Write-Host $errorstring $error&#x5B;0] $batchjob } $batchjob = @() } } ac $logfile &quot;Script finished&quot; Write-Host &quot;Job Finished&quot; Pause Exit \n\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Script was inspired by Frank Marasco&#8217;s <a href=\"https:\/\/technet.microsoft.com\/en-us\/library\/dn800987.aspx\" target=\"_blank\">post on technet<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since the inception of the OneDriveMapper script, I&#8217;ve often been asked if there is a way to pre-provision Onedrive for Business storage for users. When a user signs into Office 365 for the first time and clicks Onedrive, their Onedrive for Business storage will be allocated and initialized, before that, it is not possible to &hellip; <a href=\"https:\/\/lieben.nu\/liebensraum\/2015\/08\/provisioning-onedrive-for-business-for-all-your-users\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Provisioning Onedrive for Business for all your users<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","footnotes":""},"categories":[32,34,39,44],"tags":[],"class_list":["post-365","post","type-post","status-publish","format-standard","hentry","category-office-365","category-onedrive-for-business","category-powershell","category-sharepoint-online"],"_links":{"self":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/365","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/comments?post=365"}],"version-history":[{"count":0,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/posts\/365\/revisions"}],"wp:attachment":[{"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/media?parent=365"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/categories?post=365"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lieben.nu\/liebensraum\/wp-json\/wp\/v2\/tags?post=365"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}