Domanda

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
  }
È stato utile?

Soluzione

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

Altri suggerimenti

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top