kwizcom banner advertisement

How to Create OneDrive for Business Site Collections using PowerShell?

Requirement: OneDrive sites in Office 356 are typically created when they click on OneDrive link for the first time. In my case, for a file share to SharePoint Online OneDrive migration project, I had to pre-create OneDrive for Business sites for N number of users.

How to Create OneDrive Sites using PowerShell?
OneDrive for Business sites can be pre-created using a PowerShell cmdlet "Request-SPOPersonalSite". Open SharePoint Online Management Shell, Connect as SharePoint Online Administrator by entering the appropriate credentials to the prompt.

$AdminSiteURL="https://crescent-admin.sharepoint.com"

#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential
 
#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL –credential $Cred

#Create My Site for specific user(s)
Request-SPOPersonalSite -UserEmails "peter@crescent.com","john@crescent.com" -NoWait $True

Wait for new Minutes, SharePoint Online timer job provisions My Sites for users given in the script. You can specify up to 200 Max. Please note, This cmdlet may fail if the account is disabled or password expired.  You can verify the created OneDrive sites using:
Get-SPOSite -Template "SPSPERS" -Limit ALL -includepersonalsite $True
onedrive for business create personal site

This lists all OneDrive site collections in your tenant.

OneDrive for Business: Create Personal Site
Lets create new OneDrive sites for existing users using PowerShell CSOM.
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"

#Set parameter values
$AdminSiteURL="https://crescent-Admin.sharepoint.com/"
$UserAccounts="peter@crescent.com","john@crescent.com"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
    $Ctx.Credentials = $Credentials

    #Get Profile Loader Object
    $ProfileLoader=[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($Ctx)

    #Create onedrive for business sites
    $ProfileLoader.CreatePersonalSiteEnqueueBulk($UserAccounts)
    $ProfileLoader.Context.ExecuteQuery()

    Write-host -f Green "OneDrive for Business Sites Creation Successfully Queued!"
}
Catch {
        write-host -f Red "Error Creating OneDrive for Business Sites!" $_.Exception.Message
}
Now we started the migration project from file shares to OneDrive so that users get many new features such as : version history, metadata, recycle bin, permissions, check in/check out, auditing, web interface, etc.
How to Create OneDrive for Business Site Collections using PowerShell? How to Create OneDrive for Business Site Collections using PowerShell? Reviewed by Salaudeen Rajack on October 21, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.