Export Yammer user profile photos with PowerShell

Yammer allows you to export the users to a CSV file, but that comes without there profile picture. But there is a Yammer API, so with PowerShell and the data from the CSV file we are able to get the profile pictures as well.

Export the Yammer Users CSV file

First we need a CSV file with all the users, there for you need to be a network admin withing you Yammer site. Go to Settings > Network admin > Export Users and Export all the users.

When you open the CSV file, you will see a column with a link to the Yammer API for each user. When you open this url in you browser you will get an XML file with the users data.

In that XML file is a attribute, mugshot-url, that is the profile picture that we want.

Connect to Yammer API

Before we can interact with the Yammer API we first need to register an App so we can authorize the requests.  Patrick Lamber as written a great post about this, you can find it here. In short do the following:

  1. Make sure you are logged-in as admin to your Yammer
  2. Go to the following address: https://www.yammer.com/client_applications
  3. Register you application, you can use face address
  4. Once registered, click Generate a developer token for this application

When done copy the generated (bearer) token somewhere, we need it later.

Creating the PowerShell script

So we have a CSV file with all the users, a link to their XML file and we have a bearer token to authenticate. Time to start scripting:

Step 1 – Import the CSV file and filter the users

I added an file so you can select all users or only the active ones.

Step 2 – Create the REST API header

To download the XML file we need to be authenticated, we can do this with the bearer token that we got earlier from the Yammer Developer console.

Step 3 – Get the XML file

For each user we need to get the XML file. The invoke-webrequest returns a string, so we convert it to XML to make it easier to work with.

Step 4 – Download the Profile Photo

We download the photo with a webrequest:

Step 5 – Putting it al together

The code snippets above needs to put together, you want to loop trough the CSV users, create the output location based on there name, maybe request a different size then the default 48×48 and check if they have a photo set.

So when we combine all the peaces together we get the following script: