Forked from Benoit-Gaumard/Export_All_Yammer_Users.ps1
Created
October 24, 2022 20:23
-
-
Save rvrsh3ll/805d4bd69cb85faca571b31a10a9d0b1 to your computer and use it in GitHub Desktop.
Export all Yammer users through the Yammer REST API with PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################## | |
# Export all Yammer users through the Yammer REST API with PowerShell | |
############################################################################### | |
# Variables | |
$baererToken = "YourBaererToken" | |
$yammerBaseUrl = "https://www.yammer.com/api/v1" | |
# Function Get-BaererToken | |
Function Get-BaererToken() | |
{ | |
$headers = @{ Authorization=("Bearer " + $baererToken) } | |
return $headers | |
} | |
# Function Get-YamUsers | |
Function Get-YamUsers($page, $allUsers) | |
{ | |
if ($page -eq $null) | |
{ | |
$page = 1 | |
} | |
if ($allUsers -eq $null) | |
{ | |
$allUsers = New-Object System.Collections.ArrayList($null) | |
} | |
# Users API | |
$urlToCall = "$($yammerBaseUrl)/users.json" | |
$urlToCall += "?page=" + $page; | |
$headers = Get-BaererToken | |
Write-Host $urlToCall | |
$webRequest = Invoke-WebRequest –Uri $urlToCall –Method Get -Headers $headers | |
if ($webRequest.StatusCode -eq 200) | |
{ | |
$results = $webRequest.Content | ConvertFrom-Json | |
if ($results.Length -eq 0) | |
{ | |
return $allUsers | |
} | |
$allUsers.AddRange($results) | |
} | |
if ($allUsers.Count % 50 -eq 0) | |
{ | |
$page = $page + 1 | |
return Get-YamUsers $page $allUsers | |
} | |
else | |
{ | |
return $allUsers | |
} | |
} | |
# Call Get-YamUsers function | |
$allUsers = Get-YamUsers | |
# Export to CSV | |
$AllUsers| Export-Csv -path .\YAMMER-All-Users-$(Get-Date -format "d-M-y-hh-mm-ss").csv -Append -NoTypeInformation -Delimiter ';' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment