Home

Get Number of Members, Creation Date, and Last Post Date for All Groups in Your Network

%3CLINGO-SUB%20id%3D%22lingo-sub-133818%22%20slang%3D%22en-US%22%3EGet%20Number%20of%20Members%2C%20Creation%20Date%2C%20and%20Last%20Post%20Date%20for%20All%20Groups%20in%20Your%20Network%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-133818%22%20slang%3D%22en-US%22%3E%3CP%3EJust%20about%20all%20data%20in%20Yammer%20is%20exportable%20into%20JSON%20or%20XML%2C%20which%20might%20sound%20boring%20or%20confusing.%26nbsp%3B%20But%20it%20means%20that%20you%20can%20extract%20it%20into%20pretty%20reports%2C%20which%20isn't%20particularly%20boring.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBelow%20is%20a%20script%20that%20will%20give%20you%20basic%20information%20for%20every%20group%20in%20your%20network.%26nbsp%3B%20You%20can%20use%20this%20report%20to%20make%20administrative%20decisions%20based%20on%20the%20age%20and%20population%20size%20of%20your%20groups.%26nbsp%3B%20The%20output%20is%20a%20csv%20(spreadsheet)%2C%20with%20the%20number%20of%20members%2C%20the%20creation%20date%2C%20and%20the%20date%20that%20someone%20last%20posted%2C%20for%20every%20group%20in%20your%20network.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20use%20it%2C%20copy%20this%20code%20into%20Notepad%20and%20save%20it%20as%20a%20file%20ending%20in%20.ps1.%26nbsp%3B%20Edit%20the%20beginning%20of%20the%20file%20with%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FYammer-Developer%2FGenerating-an-Administrator-Token%2Fm-p%2F97058%22%20target%3D%22_blank%22%3Eyour%20token%3C%2FA%3E%20as%20well%20as%20what%20directories%20you%20want%20to%20use%20to%20hold%20the%20exported%20groups.csv%20file%20and%20the%20exported%20files%20that%20it%20will%20create.%26nbsp%3B%20Open%20up%20PowerShell%20and%20execute%20the%20script%20with%20.%5C%3CNAME%20your%3D%22%22%20gave%3D%22%22%20the%3D%22%22%20file%3D%22%22%3E%3C%2FNAME%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPlease%20let%20me%20know%20if%20you%20find%20this%20useful.%26nbsp%3B%20If%20so%2C%20I'll%20add%20some%20script%20around%20it%20to%20make%20it%20easier%20to%20use%2C%20and%20maybe%20we%20can%20add%20in%20number%20of%20posts%20per%20group%20and%20number%20of%20posts%20in%20last%206%20months%20as%20well.%26nbsp%3B%20%3A)%3C%2Fimg%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThanks!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23%20Gets%20usage%20information%20for%20Yammer%20Groups%0A%23%20Name%2C%20Creation%20Date%2C%20Last%20Post%20Date%2C%20Number%20of%20Members%0A%23%20%C2%A9%20Tom%20Kretzmer%20November%202017%0A%23%20Version%201.0%20(First%20complete)%0A%23This%20section%20is%20for%20you%20to%20customize%20your%20script%20for%20your%20environment%0A%23If%20the%20directories%20don't%20exist%20or%20the%20token%20is%20wrong%2C%20this%20won't%20work.%0A%0A%23This%20has%20to%20be%20YOUR%20token%0A%20%24token%20%3D%20%225620945-fUEkjdioaIkdsORLSpg4A%22%20%20%0A%0A%23This%20is%20the%20directory%20where%20your%20groups.csv%20file%20is%20stored%0A%20%24SourceDir%20%3D%20%22C%3A%5CData%5CProgramming%5CGetGroupStats%22%0A%0A%23This%20is%20the%20directory%20where%20the%20xml%20files%20and%20the%20csv%20are%20going%20to%20be%20created%0A%20%24OutputDir%20%3D%20%22C%3A%5CData%5CProgramming%5CGetGroupStats%5COutput%22%0A%0A%23%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%0A%23This%20section%20you%20shouldn't%20need%20to%20modify%0A%20%24report%20%3D%20%40()%0A%20%24line%20%3D%20new-object%20-TypeName%20PSObject%0A%20%24Headers%20%3D%20%40%7B%20%0A%20%22Accept%22%20%3D%20%22*%2F*%22%20%0A%20%22Authorization%22%20%3D%20%22Bearer%20%22%2B%24token%20%0A%20%22accept-encoding%22%20%3D%20%22gzip%22%20%0A%20%22content-type%22%3D%22application%2Fjson%22%20%0A%20%22content-length%22%20%3D%20%222%22%20%0A%20%7D%20%0A%20%0A%23import%20Group%20ID's%20that%20need%20evaluated.%20%0A%20%24groups%20%3D%20import-csv%20%24SourceDir%5CGroups.csv%0A%20%24groups%20%3D%20%24groups.id%20%0A%20%0A%23loop%20through%20all%20Group%20ID's%20%0A%20foreach%20(%24group%20in%20%24groups)%7B%20%0A%20%24line%20%3D%20new-object%20-TypeName%20PSObject%0A%0A%20%24uri%20%3D%20%22https%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fgroups%2F%24group.xml%22%20%0A%20%0A%20%24ExportedFile%20%3D%20%24OutputDir%20%2B%20%22%5C%24group.xml%22%20%0A%20%0AWrite-Host%20%24uri%20%0A(Invoke-WebRequest%20-Uri%20%24uri%20-Method%20Get%20-Headers%20%24Headers%20-passthru%20-outfile%20%24ExportedFile).content%20%20%0A%5Bxml%5D%24xmldocument%20%3D%20get-content%20%24ExportedFile%0A%0A%20%20%24Created%3D%24xmldocument.response.%22created-at%22%0A%20%20%24Created%3D%24Created.substring(0%2C10)%0A%0A%20%20%24LastPost%3D%24xmldocument.response.stats.%22last-message-at%22%0A%20%20%24LastPost%3D%24LastPost.substring(0%2C10)%0A%0A%20%24line%7C%20add-member%20-NotePropertyName%20%22Group%20Name%22%20-NotePropertyValue%20%24xmldocument.response.name%0A%20%24line%7C%20add-member%20-NotePropertyName%20%22Creation%20Date%22%20-NotePropertyValue%20%24Created%0A%20%24line%7C%20add-member%20-NotePropertyName%20%22Last%20Post%20Date%22%20-NotePropertyValue%20%24LastPost%0A%20%24line%7C%20add-member%20-NotePropertyName%20%22Number%20of%20Members%22%20-NotePropertyValue%20%24xmldocument.response.stats.members%0A%0A%0AWrite-Host%20%24line%0A%20%24report%20%2B%3D%20%24line%0A%20%7D%0AWrite-Host%20%3D%3D%3DEND%3D%3D%3D%0A%24report%7Cexport-csv%20%24OutputDir%5Creport.csv%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-133818%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EREST%20API%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EYammer%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-135505%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20Number%20of%20Members%2C%20Creation%20Date%2C%20and%20Last%20Post%20Date%20for%20All%20Groups%20in%20Your%20Network%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-135505%22%20slang%3D%22en-US%22%3E%3CP%3EHere's%20a%20similar%20script.%26nbsp%3B%20This%20one%20will%20find%20any%20group%20you%20might%20have%20which%20does%20not%20have%20an%20administrator%20assigned%2C%20aka%20%22Orphan%20Groups%22.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOne%20caveat%2C%20if%20the%20only%20admins%20remaining%20for%20a%20group%20are%20also%20Verified%20Admins%2C%20that%20group%20may%20be%20returned%20as%20a%20false%20positive.%26nbsp%3B%20Technically%20there%20are%20no%20admins%20assigned%20for%20that%20group%2C%20but%20if%20a%20Verified%20Admin%20is%20merely%20a%20member%20of%20a%20group%2C%20they%20show%20up%20as%20admins%20for%20the%20group%20automatically.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20a%20good%20thing%20to%20run%20once%20in%20a%20while%20to%20find%20groups%20which%20have%20been%20left%20without%20an%20administrator%2C%20usually%20by%20normal%20organization%20attrition.%26nbsp%3B%20Community%20managers%20should%20go%20and%20follow%20up%20with%20these%20groups%20and%20get%20new%20admins%20assigned%2C%20to%20help%20drive%20success%20of%20these%20groups.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%23%20Gets%20status%20and%20admin%20information%20for%20Yammer%20Groups%3CBR%20%2F%3E%23%20Primarily%20to%20find%20orphaned%20groups%20(no%20assigned%20group%20admin)%3CBR%20%2F%3E%23%20Group%20ID%2C%20Name%2C%20Has%20Admin%2C%20Status%3CBR%20%2F%3E%23%20%C2%A9%20Tom%20Kretzmer%20December%202017%3CBR%20%2F%3E%23%20Version%201.0%20(First%20complete)%3CBR%20%2F%3E%3CBR%20%2F%3E%23This%20section%20is%20for%20you%20to%20customize%20your%20script%20for%20your%20environment%3CBR%20%2F%3E%23If%20the%20directories%20don't%20exist%20or%20the%20token%20is%20wrong%2C%20this%20won't%20work.%3CBR%20%2F%3E%3CBR%20%2F%3E%23This%20has%20to%20be%20YOUR%20token%3CBR%20%2F%3E%20%24token%20%3D%20%225620945-fUEkjdioaIkdsORLSpg4A%22%20%3CBR%20%2F%3E%3CBR%20%2F%3E%23This%20is%20the%20directory%20where%20your%20groups.csv%20file%20is%20stored%3CBR%20%2F%3E%20%24SourceDir%20%3D%20%22C%3A%5CData%5CProgramming%5CFindOrphanGroups%22%3CBR%20%2F%3E%3CBR%20%2F%3E%23This%20is%20the%20directory%20where%20the%20xml%20files%20and%20the%20csv%20are%20going%20to%20be%20created%3CBR%20%2F%3E%20%24OutputDir%20%3D%20%22C%3A%5CData%5CProgramming%5CFindOrphanGroups%5COutput%22%3CBR%20%2F%3E%3CBR%20%2F%3E%23%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3D%3CBR%20%2F%3E%23This%20section%20you%20shouldn't%20need%20to%20modify%3CBR%20%2F%3E%20%24report%20%3D%20%40()%3CBR%20%2F%3E%20%24line%20%3D%20new-object%20-TypeName%20PSObject%3CBR%20%2F%3E%20%24Headers%20%3D%20%40%7B%20%3CBR%20%2F%3E%20%22Accept%22%20%3D%20%22*%2F*%22%20%3CBR%20%2F%3E%20%22Authorization%22%20%3D%20%22Bearer%20%22%2B%24token%20%3CBR%20%2F%3E%20%22accept-encoding%22%20%3D%20%22gzip%22%20%3CBR%20%2F%3E%20%22content-type%22%3D%22application%2Fjson%22%20%3CBR%20%2F%3E%20%22content-length%22%20%3D%20%222%22%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%23import%20Group%20ID's%20that%20need%20evaluated.%20%3CBR%20%2F%3E%20%24groups%20%3D%20import-csv%20%24SourceDir%5CGroups.csv%3CBR%20%2F%3E%20%24groups%20%3D%20%24groups.id%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%23loop%20through%20all%20Group%20ID's%20%3CBR%20%2F%3E%20foreach%20(%24group%20in%20%24groups)%7B%20%3CBR%20%2F%3E%20%24line%20%3D%20new-object%20-TypeName%20PSObject%3CBR%20%2F%3E%3CBR%20%2F%3E%20%24uri%20%3D%20%22https%3A%2F%2Fwww.yammer.com%2Fapi%2Fv1%2Fgroups%2F%24group.xml%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24ExportedFile%20%3D%20%24OutputDir%20%2B%20%22%5C%24group.xml%22%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3E(Invoke-WebRequest%20-Uri%20%24uri%20-Method%20Get%20-Headers%20%24Headers%20-outfile%20%24ExportedFile).content%20%3CBR%20%2F%3E%5Bxml%5D%24xmldocument%20%3D%20get-content%20%24ExportedFile%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%20%24line%7C%20add-member%20-NotePropertyName%20%22Group%20ID%22%20-NotePropertyValue%20%24group%3CBR%20%2F%3E%20%24line%7C%20add-member%20-NotePropertyName%20%22Group%20Name%22%20-NotePropertyValue%20%24xmldocument.response.name%3CBR%20%2F%3E%20%24line%7C%20add-member%20-NotePropertyName%20%22Has%20Admin%22%20-NotePropertyValue%20%24xmldocument.response.%22has-admin%22%3CBR%20%2F%3E%20%24line%7C%20add-member%20-NotePropertyName%20%22Status%22%20-NotePropertyValue%20%24xmldocument.response.state%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3EWrite-Host%20Checking%20%24xmldocument.response.name%20for%20admins%3CBR%20%2F%3E%20%24report%20%2B%3D%20%24line%3CBR%20%2F%3E%20%7D%3CBR%20%2F%3EWrite-Host%20%3D%3D%3DEND%3D%3D%3D%3CBR%20%2F%3E%24report%7Cexport-csv%20%24OutputDir%5Creport.csv%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Tom Kretzmer
Regular Contributor

Just about all data in Yammer is exportable into JSON or XML, which might sound boring or confusing.  But it means that you can extract it into pretty reports, which isn't particularly boring.  

 

Below is a script that will give you basic information for every group in your network.  You can use this report to make administrative decisions based on the age and population size of your groups.  The output is a csv (spreadsheet), with the number of members, the creation date, and the date that someone last posted, for every group in your network.

 

To use it, copy this code into Notepad and save it as a file ending in .ps1.  Edit the beginning of the file with your token as well as what directories you want to use to hold the exported groups.csv file and the exported files that it will create.  Open up PowerShell and execute the script with .\<name your gave the file>

 

Please let me know if you find this useful.  If so, I'll add some script around it to make it easier to use, and maybe we can add in number of posts per group and number of posts in last 6 months as well.  :)

 

Thanks!

 

# Gets usage information for Yammer Groups
# Name, Creation Date, Last Post Date, Number of Members
# © Tom Kretzmer November 2017
# Version 1.0 (First complete)
#This section is for you to customize your script for your environment
#If the directories don't exist or the token is wrong, this won't work.

#This has to be YOUR token
 $token = "5620945-fUEkjdioaIkdsORLSpg4A"  

#This is the directory where your groups.csv file is stored
 $SourceDir = "C:\Data\Programming\GetGroupStats"

#This is the directory where the xml files and the csv are going to be created
 $OutputDir = "C:\Data\Programming\GetGroupStats\Output"

#==================================
#This section you shouldn't need to modify
 $report = @()
 $line = new-object -TypeName PSObject
 $Headers = @{ 
 "Accept" = "*/*" 
 "Authorization" = "Bearer "+$token 
 "accept-encoding" = "gzip" 
 "content-type"="application/json" 
 "content-length" = "2" 
 } 
 
#import Group ID's that need evaluated. 
 $groups = import-csv $SourceDir\Groups.csv
 $groups = $groups.id 
 
#loop through all Group ID's 
 foreach ($group in $groups){ 
 $line = new-object -TypeName PSObject

 $uri = "https://www.yammer.com/api/v1/groups/$group.xml" 
 
 $ExportedFile = $OutputDir + "\$group.xml" 
 
Write-Host $uri 
(Invoke-WebRequest -Uri $uri -Method Get -Headers $Headers -passthru -outfile $ExportedFile).content  
[xml]$xmldocument = get-content $ExportedFile

  $Created=$xmldocument.response."created-at"
  $Created=$Created.substring(0,10)

  $LastPost=$xmldocument.response.stats."last-message-at"
  $LastPost=$LastPost.substring(0,10)

 $line| add-member -NotePropertyName "Group Name" -NotePropertyValue $xmldocument.response.name
 $line| add-member -NotePropertyName "Creation Date" -NotePropertyValue $Created
 $line| add-member -NotePropertyName "Last Post Date" -NotePropertyValue $LastPost
 $line| add-member -NotePropertyName "Number of Members" -NotePropertyValue $xmldocument.response.stats.members


Write-Host $line
 $report += $line
 }
Write-Host ===END===
$report|export-csv $OutputDir\report.csv

 

1 Reply
Highlighted

Here's a similar script.  This one will find any group you might have which does not have an administrator assigned, aka "Orphan Groups".

 

One caveat, if the only admins remaining for a group are also Verified Admins, that group may be returned as a false positive.  Technically there are no admins assigned for that group, but if a Verified Admin is merely a member of a group, they show up as admins for the group automatically.

 

This is a good thing to run once in a while to find groups which have been left without an administrator, usually by normal organization attrition.  Community managers should go and follow up with these groups and get new admins assigned, to help drive success of these groups.

 

# Gets status and admin information for Yammer Groups
# Primarily to find orphaned groups (no assigned group admin)
# Group ID, Name, Has Admin, Status
# © Tom Kretzmer December 2017
# Version 1.0 (First complete)

#This section is for you to customize your script for your environment
#If the directories don't exist or the token is wrong, this won't work.

#This has to be YOUR token
$token = "5620945-fUEkjdioaIkdsORLSpg4A"

#This is the directory where your groups.csv file is stored
$SourceDir = "C:\Data\Programming\FindOrphanGroups"

#This is the directory where the xml files and the csv are going to be created
$OutputDir = "C:\Data\Programming\FindOrphanGroups\Output"

#==================================
#This section you shouldn't need to modify
$report = @()
$line = new-object -TypeName PSObject
$Headers = @{
"Accept" = "*/*"
"Authorization" = "Bearer "+$token
"accept-encoding" = "gzip"
"content-type"="application/json"
"content-length" = "2"
}

#import Group ID's that need evaluated.
$groups = import-csv $SourceDir\Groups.csv
$groups = $groups.id

#loop through all Group ID's
foreach ($group in $groups){
$line = new-object -TypeName PSObject

$uri = "https://www.yammer.com/api/v1/groups/$group.xml"

$ExportedFile = $OutputDir + "\$group.xml"


(Invoke-WebRequest -Uri $uri -Method Get -Headers $Headers -outfile $ExportedFile).content
[xml]$xmldocument = get-content $ExportedFile


$line| add-member -NotePropertyName "Group ID" -NotePropertyValue $group
$line| add-member -NotePropertyName "Group Name" -NotePropertyValue $xmldocument.response.name
$line| add-member -NotePropertyName "Has Admin" -NotePropertyValue $xmldocument.response."has-admin"
$line| add-member -NotePropertyName "Status" -NotePropertyValue $xmldocument.response.state


Write-Host Checking $xmldocument.response.name for admins
$report += $line
}
Write-Host ===END===
$report|export-csv $OutputDir\report.csv

 

Related Conversations