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 = "[email protected]"
$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