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. Function GetUserByEmail
  7. {
  8. # Invoke Web Request
  9. $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
  10. # Check whether the status code is 200
  11. if ($webRequest.StatusCode -eq 200) {
  12. # Converts a JSON-formatted string to a custom object or a hash table.
  13. $user = $webRequest.Content | ConvertFrom-Json
  14. write-host -ForegroundColor Green "Full Name: " $user.full_name " - Location: " $user.Location
  15. }
  16. else {
  17. Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
  18. }
  19. }
  20. # Call the function
  21. 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.