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 = "test@domainO365Dev.onmicrosoft.com" 
   $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
  }
  • 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 '16 at 12:10
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

  • I did as you suggested, the issue still persists – spStacker Sep 3 '16 at 16:23
  • Chaning the path to 16 hive did the trick.. I think there was some caching problem in the powershell management shell – spStacker Sep 6 '16 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, privacy policy and cookie policy

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