How to extract the list of Group members as a CSV file?

Highlighted
Contributor

Hi everyone, 

 

Please find another usefull script I made helping me to extract the list of yammer group member as a CSV file. It is quite usefull if you need to (some example of use case) : 

* make a backup of group member within a group

* extract the list of group member (to not send an announcement but an email)

* extract the list of group member (to make a gap analysis), as example, you have another list with all employee within a given category (ie Job) and you want to enforce/reinforce/onboard missing one within your group.

* extract the list of group member to add them in bulk into another one (ie. if you want to merge 2 group together).

 

@Tom Kretzmer you will also like that one ;)

 

 

#
# Name : getYammerGroupMembers.ps1
# By : Eric JENOUVRIER
# Description : A tiny powershell script to extract yammer group member as a csv file
#
# Typical usage : you need to not send an Announcement but an email to all group members
# or you need to make the list of all group member to make some gap analysis with some other list
# or you need to make the list to invite in bulk all group members into another one (ie. merge 2 groups)
#
# Important : For confidentiality reason, the $Token value was obfuscate. 
# You need to replace the $Token value by your own private network value.
#
# Warning : never ever, share a script on which your secure token is in clear, 
# else you give access to your private network ...
#
# Usage : you need to change the $GroupId value (1234567) in this example with the Yammer Group ID
# of the group on which you want to extract group members. How to get the Group ID ? it is quite simple
# Let take this example of URL : https://www.yammer.com/itpronetwork/#/threads/inGroup?type=in_group&feedId=5258215
# This Yammer Group have as Group ID : 5258215
#

$GroupId=1234567;

$Token = "5****-A********************Q"

$Headers = @{
        "Authorization" = "Bearer "+$Token
}
  
$GroupCycle = 1
DO
	{
		$GetMoreGroupsUri = "https://www.yammer.com/api/v1/users/in_group/$GroupId.xml?page=$GroupCycle"
		write-host ("REST API CALL : $GetMoreGroupsUri")
        [xml]$Xml = ((Invoke-WebRequest -Uri $GetMoreGroupsUri -Method Get -Headers $Headers).content)
        $YammerGroups += $Xml.response.users.user
        $GroupCycle ++
        $GroupCount += $Xml.response.users.user.count
		write-host ("GROUPMEMBER COUNT : $GroupCount")
    }	
	While ($Xml.response.users.user.count -gt 0)

	$YammerGroups | Export-Csv "$GroupId.csv" -Delimiter ";" 
	
24 Replies
Highlighted

I'd like to try this, but I have no idea how I can find out what my token value is.

 

Where can I get that?

Highlighted

Many thanx for sharing @Eric JENOUVRIER

 

May you help me with this :

- i have a group with 66 members

- when i use your script, the Do section repeats until page 3, and so it appends 3 times the previous user values within the scv file

- I am not sure to understand the following statement :

While ($Xml.response.users.user.count -gt 0)

 

- Finally, i have an error message each time i execute your script, although the csv file is correctly generated :

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.
At line:44 char:18
+ ... merGroups | Export-Csv "D:\ATG\YAMMER\DOCUMENTATION\Scripts\output\at ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

Many thanx for your feedback,

 

Highlighted
Hi,
Within Yammer, Click the ellipsis, Apps, Register new app, Get Token, that's it
Everything is explained here : https://developer.yammer.com/docs/getting-started

Highlighted
It is quite basic Alexis, result are deliver by "page", so the loop continue until it reach a page containing 0 record (the first loop get 50 result, the 2nd loop 16 result and the 3rd loop 0 result (and stop).
Highlighted
Hi Ingeborg, here is a write-up on creating your token: https://developer.yammer.com/docs/test-token
Highlighted

Oh i see @Eric JENOUVRIER, your idea here was essentially to automate what @Tom Kretzmer had primarily done, ok i understand :)

 

Many thanx for your feedback ;)

Highlighted

In addition to the other great answers here, I wanted to quote an old article of mine about getting the token (once you have that token, a whole new world of administrative power opens up to you, so I've had this conversation many times):

 

You need something called a REST token. Two things to know about this.

 

First – be careful with this token. Guard it. It’s the security equivalent of your username and password. And since you’re probably a Yammer Verified Admin, someone finding and using this token could really be a big problem for your network.

 

Second – this process is a pain. Seriously. I’ll try to write a script to make it easier, but for now, unfortunately, the best available documentation is here: https://developer.yammer.com/docs/test-token

 

I’ll wait while you read that. And yes, like I said, it is a pain. Sorry.

 

When you’re done, you’ll have your token. It’ll be something like this: GwrtnFHPU59EL1CUFeuEbe

 

Ok, that is literally the hardest part of this whole process. Don’t be embarrassed asking for help from your local developers or the Yammer Developer group.

Highlighted

I found somewhere how to get the token with Fiddler. Not easy, either, but I can see why it SHOULD be hard. 

 

Thanks for all the comments.

Highlighted

@Ingeborg Hawighorst wrote:

I'd like to try this, but I have no idea how I can find out what my token value is.

 

Where can I get that?


Login into Yammer using your admin verified account using either  IE, Firefox or googlechrome press F12 go to network look for Yammer in the summary list once found highlight and click details go to cookies look for OAUTH token.

Highlighted

Wow. Thanks @Vivien Millar, but it's a bit hard to understand these instructions without any punctuation. 

Highlighted

@Deletedalready provided perfect instructions about how to get the token, it's far easier than it used to be and there's no need for fiddler anymore. Maybe it's just me, but I feel that reading the other posts in a thread is a good way to find if your question is already answered.

Highlighted

I'm not a developer and frankly, the steps for the yammer dev thing freak me out.  I find the Fiddler approach much less intrusive, since I only observe what's already there and I don't need to create a fake new app to get a token.

Highlighted

If that way works a lot better for you, then by all means that's a great way to go.  :)  Let us know if you run into any issues with that route.


Highlighted

I appreciate this a lot. 

 

Personally, I've been messing around with doing the same thing but I've used the ConvertFrom-Json | % {$_.Rows} method to export to csv. 

 

I figured since the request was already in json I should use that - is there a reason you prefer using XML? I'm just really getting into using PowerShell for my Yammer admin needs and just wanted to pick your brain @Eric JENOUVRIER

Highlighted

I prefered to use XML for 2 reasons :

1) highlight it is possible to query Yammer API in XML (because some people not know)

2) it was easier (for me) to manipulate the structure and substructure

 

But at the very end, in the 2 case : JSON or XML, you have a structured response from the API, so use the API response format you prefer :)

Highlighted
Thanks! Makes perfect sense. Also - you were right...I didn't know it was even possible to query in XML and wouldn't even have thought about it when I was writing my script.
Highlighted

This is great!  I am in the middle of moving sone yammer groups manually!  I am getting an error though.

 

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.At line:43 char:18
+ $YammerGroups | Export-Csv "$GroupId.csv" -Delimiter ";"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

 

Any ideas?  Note: i am no developer and am just following these instructions!!

Highlighted

Actually the output worked.  Still get the error but it works.  Wow this is a great help!!!


@chetan wrote:

This is great!  I am in the middle of moving sone yammer groups manually!  I am getting an error though.

 

Export-Csv : Cannot bind argument to parameter 'InputObject' because it is null.At line:43 char:18
+ $YammerGroups | Export-Csv "$GroupId.csv" -Delimiter ";"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Export-Csv], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ExportCsvCommand

 

Any ideas?  Note: i am no developer and am just following these instructions!!


 

Highlighted

Where can you view the output?  I didn't see a file.