To learn how to use this script, please refer to: How to: Synchronize Online and Local Files
########
#One Drive For Business Provisioning
#Script help: http://www.lieben.nu
#Purpose: Provision One Drive for all users in Office 365
########
#Requirements:
########
<#MS Online Services Signin Assistant:
https://www.microsoft.com/en-us/download/details.aspx?id=41950
Azure AD Module (x64):
http://social.technet.microsoft.com/wiki/contents/articles/28552.microsoft-azure-active-directory-powershell-module-version-release-history.aspx
Powershell 4
.NET 4.5
Sharepoint Server 2013 Client Components
http://www.microsoft.com/en-us/download/details.aspx?id=35585
SharePoint Management Shell
https://www.microsoft.com/en-us/download/details.aspx?id=35588
run “Set-Executionpolicy Unrestricted” in an elevated powershell window
Windows 7+ or Windows Server 2008+
#>
$o365login = "admin@companyname.onmicrosoft.com" #Username of O365 Admin
$o365pw = "YourPassword" #Password of O365 Admin
$logfile = ($env:APPDATA + "\ODFB_BP.log") #Logfile in case of errors
$spURL = "https://yourcompanyname-admin.sharepoint.com" #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
#Start script
ac $logfile "-----$(Get-Date) ODFB_BP v0.2 $($env:COMPUTERNAME) Session log-----`n"
#build Credential Object
$secpasswd = ConvertTo-SecureString $o365pw -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential ($o365login, $secpasswd)
#Load sharepoint module
try{
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles") | Out-Null
}catch{
$errorstring = "ERROR: Failed to load Sharepoint Libraries, exiting"
ac $logfile $errorstring
Write-Host $errorstring
Pause
Exit
}
#load Azure module
$env:PSModulePath += ";C:\Windows\System32\WindowsPowerShell\v1.0\Modules\"
try{
Import-Module msonline
}catch{
$errorstring = "ERROR: Failed to load Azure module, exiting"
ac $logfile $errorstring
ac $logfile $error[0]
Write-Host $errorstring
Pause
Exit
}
#connect to MSOL
try{
Connect-MsolService -Credential $Credentials
}catch{
$errorstring = "Critical error, unable to connect to O365, check the credentials"
ac $logfile $errorstring
ac $logfile $error[0]
Write-Host $errorstring
Pause
Exit
}
#fetch all UPN's
$users = Get-MsolUser -All | Select-Object UserPrincipalName
#Build sP object
$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 = "Critical error, unable to connect to Sharepoint Online, check admin url and credentials"
ac $logfile $errorstring
ac $logfile $error[0]
Write-Host $errorstring $error[0]
Pause
Exit
}
$loader =[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[$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 = "Critical error, unable to create bulk provisioning job in Sharepoint Online"
ac $logfile $errorstring
ac $logfile $error[0]
ac $logfile $batchjob
Write-Host $errorstring $error[0] $batchjob
}
$batchjob = @()
}
}
ac $logfile "Script finished"
Write-Host "Job Finished"
Pause
Exit