Null is returned when I try to retrieve User profile properties of people manager object in Powershell RRS feed

  • Question

  • I am successfully connected to the Tenant admin site of SharePoint online tenancy and then when I try to loop through the GET-ADMember commandlet of particular  AD group I am always getting null for Getpropertiesfor($Accountname) method of people manager object. Although I found that context is available.

    Please help me to solve this problem as I am trying hard for few days but with no luck.

    Thanks in advance :)

    Wednesday, February 1, 2017 10:24 AM

All replies

  • I can execute the code successfully in development environment but only not in the server.
    Wednesday, February 1, 2017 10:25 AM
  • Hi Sujan,

    Please make sure the Accountname is valid in the Tenant server and the parameter for Getpropertiesfor method shoud be the user login name, below is a demo about getting user propeties using SharePoint Online PowerShell:

    #Import the required DLL
    Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
    #Mysite URL
    $site = ''
    #Admin User Principal Name
    $admin = 'Admin@Domain.OnMicrosoft.Com'
    #Get Password as secure String
    $password = Read-Host 'Enter Password' -AsSecureString
    #Get the Client Context and Bind the Site Collection
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin , $password)
    $context.Credentials = $credentials
    #Fetch the users in Site Collection
    $users = $context.Web.SiteUsers
    #Create an Object [People Manager] to retrieve profile information
    $people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context)
    $collection = @()
    Foreach($user in $users)
        $userprofile = $people.GetPropertiesFor($user.LoginName)
        if($userprofile.Email -ne $null)
            $upp = $userprofile.UserProfileProperties
            $profileData = "" | Select "FirstName" , "LastName" , "WorkEmail" , "Title" , "Responsibility"
            $profileData.FirstName = $upp.FirstName
            $profileData.LastName = $upp.LastName
            $profileData.WorkEmail = $upp.WorkEmail
            $profileData.Responsibility = $upp.'SPS-Responsibility'
            $collection += $profileData
    $collection | Export-Csv C:\Temp\SPO-UserInformation.csv -NoTypeInformation -Encoding UTF8


    Best Regards`

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Thursday, February 2, 2017 4:14 AM
  • Hi Jerry,

    Thanks for looking into the issue. But unfortunately I am getting the same error too with the code you provided.

    Exception calling "ExecuteQuery" with "0" argument(s): "The underlying connection was closed: An unexpected error 
    occurred on a receive."
    At line:23 char:1
    + $context.ExecuteQuery()
    + ~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : WebException

    I am not sure if this is a problem with the server itself. Can you suggest if any components that could be missing or any updates required?

    Friday, February 3, 2017 11:57 AM
  • Hi Sujan,

    Please check if the referenced dll is valid, it should be SharePoint Online CSOM, Here is my tested code in my environment and it worked as expected:

    Also, please check if the credential passed in the code has enough permission to read user profile properties.

    If the issue still existed, please post your code for deep research.


    Best Regards

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Wednesday, February 8, 2017 9:25 AM