How To Get A User By Email Address In Yammer Using PowerShell

In this blog, you will see how to get a user by their email address in Yammer using PowerShell.

Prerequisites

Go to https://www.yammer.com/client_applications and register an app.

Once the app is registered, generate a developer token.

Copy the below script and paste it in a Notepad. Save the file as GetUserByEmail.ps1.

  1. # Input Parameters    
  2. $developerToken = "461-*****YOkutfuKoWUEmWPg"    
  3. $userEmail="[email protected]"    
  4. $headers = @{ Authorization=("Bearer " + $developerToken) }      
  5. $uri="https://www.yammer.com/api/v1/users/by_email.json?email="+$userEmail  
  6.   
  7.     
  8. Function GetUserByEmail    
  9. {      
  10.     # Invoke Web Request    
  11.     $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers    
  12.     
  13.     # Check whether the status code is 200    
  14.     if ($webRequest.StatusCode -eq 200) {    
  15.         
  16.         # Converts a JSON-formatted string to a custom object or a hash table.     
  17.         $user = $webRequest.Content | ConvertFrom-Json          
  18.           
  19.         write-host -ForegroundColor Green "Full Name: " $user.full_name  " - Location: " $user.Location      
  20.     }    
  21.     else {    
  22.         Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status    
  23.     }    
  24. }    
  25.     
  26. # Call the function    
  27. GetUserByEmail    

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetUserByEmail.ps1 file location

Run the following command.

  1. >.\GetUserByEmail.ps1

Reference

https://developer.yammer.com/docs/usersby_emailjsonemailuserdomaincom

Thus, in this blog, you saw how to get a user by email address in Yammer using PowerShell.