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.
- # Input Parameters
- $developerToken = "461-*****YOkutfuKoWUEmWPg"
- $userEmail="[email protected]"
- $headers = @{ Authorization=("Bearer " + $developerToken) }
- $uri="https://www.yammer.com/api/v1/users/by_email.json?email="+$userEmail
-
-
- Function GetUserByEmail
- {
- # Invoke Web Request
- $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
-
- # Check whether the status code is 200
- if ($webRequest.StatusCode -eq 200) {
-
- # Converts a JSON-formatted string to a custom object or a hash table.
- $user = $webRequest.Content | ConvertFrom-Json
-
- write-host -ForegroundColor Green "Full Name: " $user.full_name " - Location: " $user.Location
- }
- else {
- Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
- }
- }
-
- # Call the function
- GetUserByEmail
Open PowerShell window and run the following command.
folderlocation – GetUserByEmail.ps1 file location
Run the following command.
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.