Question

My issue is similar to another posted here on the site but still happening(Office 365 pre-provision my site issue with Powershell). I've tried to run this on 3 different machines and 1 works, the other two don't.

The following assemblies are installed and loaded on all 3 machines with the same version:

SharePoint Client Components: 16.0.4002.1211
MS Online Services Sign-In Assistant: 7.250.4556.0
Azure AD Module for Windows: 1.0.0 **(I don't think this one is needed)**

On one machine (my laptop), I get an error on the line:

$loader =[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($ctx)

ERROR:

Cannot convert argument "context", with value: "Microsoft.SharePoint.Client.ClientContext", for "GetProfileLoader" to type "Microsoft.SharePoint.Client.ClientRuntimeContext": "Cannot convert the "Microsoft.SharePoint.Client.ClientContext" value of type "Microsoft.SharePoint.Client.ClientContext" to type "Microsoft.SharePoint.Client.ClientRuntimeContext"."

On the other machine (2013 SP WFE), the error is on line:

$loader.CreatePersonalSiteEnqueueBulk(@("$user$Domain")) 

Error:

One Drive Not Provisioned Method invocation failed because [Microsoft.SharePoint.Client.UserProfiles.ProfileLoader] does not contain a method named 'CreatePersonalSiteEnqueueBulk'.

I know I'm missing an assembly, reference, version or something but I can't figure out what it is.

cls
$Domain = "@mydomain.com"

Write-Host "Load SharePoint and One Drive Assemblies" -ForegroundColor Yellow
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
#Must be SharePoint Administrator URL
$webUrl = "https://SiteDomain-admin.sharepoint.com"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($webUrl)

Write-Host "Create Connection To Administration Site" -ForegroundColor Yellow   
$web = $ctx.Web
$username = "me@myDomain.com"
$password = ConvertTo-SecureString '*************' -AsPlainText -Force

$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$password )

Write-Host "Load website into cache" -ForegroundColor Yellow
$ctx.Load($web)
$ctx.ExecuteQuery()

$loader =[Microsoft.SharePoint.Client.UserProfiles.ProfileLoader]::GetProfileLoader($ctx)

#To get the profile
$profile = $loader.GetUserProfile()
$ctx.Load($profile)
$ctx.ExecuteQuery()
#$profile 

Write-Host "Loading User Array" -ForegroundColor Yellow
$UserArray = "User1", "User2", "User3","User4"
Foreach ($user in $UserArray)
{
    try{
        #To queue up the profile
        $loader.CreatePersonalSiteEnqueueBulk(@("$user$Domain")) 
        $loader.Context.ExecuteQuery()
        Write-Host "$user One Drive Provisioned" -ForegroundColor Cyan
    }catch{
        Write-Host "$user One Drive Not Provisioned" $_.Exception.Message -ForegroundColor Red
    }
}
Write-Host "COMPLETED"  -ForegroundColor Green
Was it helpful?

Solution

You don't need to do all that work anymore. In a recent update to the SharePoint Online Management Shell, there is a commandlet to do this for you with much less effort.

It is Request-SPOPersonalSite. You can enqueue up to 200 OneDrive for Business sites at a time.

$emails = "user1@contoso.com,user2@contoso.com"
Request-SPOPersonalSite -UserEmails $emails

If you are going to do batches of 200 at a time, it is recommended to use the -NoWait switch.

Request-SPOPersonalSite -UserEmails $emails -NoWait

https://technet.microsoft.com/en-us/library/dn792367.aspx

OTHER TIPS

There are two errors on this Microsoft page.

  1. In addition to being an admin account, the account doing the provisioning MUST be licensed for SharePoint Online.
  2. The syntax of the PowerShell was incorrect in the original Microsoft page.  The emails should be EACH in quotes, separated by a comma ("mail1","mail2")
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top