7

Hi Below is the error i am getting while running the powershell script Error

Cannot find an overload for "PeopleManager" and the argument count: "1

Script:

#Importing PowerShell Module
    Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking


#Authenticating User to SharePoint Online
   $username = "[email protected]" 
   $Adminurl = "https://sp-admin.sharepoint.com/sites/Dev"
   $siteColUrl = "https://test365dev.sharepoint.com"

#Logging Method for errors
   $DATE = get-date
   $LogPath = "logpath"
   $LogFileName = "LogFileName.log"

$FilePath = $LogPath +"\" + $LogFileName
$logFileCreated = $False
function write-log([string]$label, [string]$logMsg)
{ 

    if($logFileCreated -eq $False)
    {
        write-host "Creating log file..."
        if((Test-Path -path $LogPath) -ne $True)
        {
            write-host"Provide proper values to LogPath folder" -ForegroundColor Red
        }
        else
        {
            Add-Content -Path $FilePath -Value $logHeader
            $script:logFileCreated  = $True
            write-host "Log file created..."
            [string]$info = [System.String]::Format("[$Date] {0}: {1}",$label, $logMsg)
            Add-Content -Path $FilePath -Value $info
        }
    }
    else
    {
        [string]$info = [System.String]::Format("[$Date] {0}: {1}",$label, $logMsg)
        Add-Content -Path $FilePath -Value $info
    }
 }

try
{
   Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
   Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
   Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"


   #Bind to site collection
   $password = Read-Host -Prompt "Enter password" -AsSecureString 
   $Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteColUrl)
   $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$Password)
   $Context.Credentials = $Creds
   Write-Host "Successfully connected.." -ForegroundColor Green


   #Retrieve lists
   $web = $Context.Web
   $Users = $Context.Web.SiteUsers
   $Context.Load($Users)
   $Context.Load($web)
   $Context.ExecuteQuery()

   $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
    Foreach ($User in $Users)
    {  
      $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
      Write-Host "user profile value: " + $UserProfile
      $Context.ExecuteQuery()
      If ($UserProfile.Email -ne $null)
        {
          Write-Host "User:" $UserProfile.Email -ForegroundColor Green
          $UserProfile.UserProfileProperties
        }  
    }
}
  catch
       { 
          write-log "Error: " $_.Exception.Message
  }
1
  • Can you give some details on the error? Line in script or so? I commented out the first line (Import-Module) but the rest of the script ran fine for me...
    – Nils
    Sep 6, 2016 at 12:10

2 Answers 2

5
+50

This is because you are referring 2013 Client SDK dll's.. Look the path points to 15 hive

You should install SPO Client SDK and change to 16 hive in Add-Type

https://www.microsoft.com/en-us/download/details.aspx?id=42038

2
  • I did as you suggested, the issue still persists
    – SandeshR
    Sep 3, 2016 at 16:23
  • Chaning the path to 16 hive did the trick.. I think there was some caching problem in the powershell management shell
    – SandeshR
    Sep 6, 2016 at 15:00
2

Most likely you are not binding to the right context. If you are working with the UserProfile, you need to bind your context to the My Site host, https://tenant-my.sharepoint.com.

Your Answer

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

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