4

I am trying to connect to the Microsoft.SharePoint.Client.UserProfiles.dll however keep getting the message -

New-Object : Cannot find an overload for "PeopleManager" and the argument count: "1".
At line:26 char:18
+ ... leManager = New-Object Microsoft.SharePoint.Client.UserProfiles.Peopl ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand

The script is this test script here which just picks up all user profiles and writes each one out (got this from here)

#Specify tenant admin and URL
$User = "USERACCOUNT.onmicrosoft.com"

#Configure Site URL and User
$SiteURL = "https://TENANT-admin.sharepoint.com"


[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")


$Password =  Read-Host -Prompt "Please enter your password" -AsSecureString
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)

#Bind to Site Collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Creds

#Identify users in the Site Collection
$Users = $Context.Web.SiteUsers
$Context.Load($Users)
$Context.ExecuteQuery()

#Create People Manager object to retrieve profile data
$PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
Foreach ($User in $Users)
{
    $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
    $Context.Load($UserProfile)
    $Context.ExecuteQuery()
    If ($UserProfile.Email -ne $null)
    {
        Write-Host "User:" $User.LoginName -ForegroundColor Green
        $UserProfile.UserProfileProperties
        Write-Host ""
    }  
}

I have tried the following - change the URL

I thought maybe they couldn't find the reference to the DLL but I can see powershell is picking them up

enter image description here

They are also here if I reference them directly as I downloaded the SDK for SP online

enter image description here

If anyone has any pointers I would be grateful.

Thanks

2 Answers 2

3

You should try downloading latest version of CSOM dlls from nuget repository and check if that works.

I had a similar problem a while ago, when I couldn't get some properties that should've been there according to msdn documentation, and getting the latest csom dlls solved the problem.

2
  • Thank you very much, this resolved the issue. I was out of ideas. For anyone who has never used VS like me you have to download the free version, create an empty project, follow the steps from the link above provided by Damjan Tomic, and then once the dlls are downloaded you can run your PS script no issues this time. Thanks again.
    – Jamie_lee
    Commented Apr 13, 2017 at 15:24
  • 1
    That is really strange. I just tested your script with v15 dlls (sharepoint 2013) and it worked fine. Must have been a bug in the version you were using.
    – Bunzab
    Commented Apr 13, 2017 at 15:27
0

Thank you.

That was it, I had to download the packages from Nuget and open new ISE console. Then it worked for me.

Bare in mind, Even when creating new windows (ctrl+T) in ISE, it didn't worked out for me. Only creating completely new instance of ISE worked for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.