Download All Files in a Group

Regular Contributor

Today I was asked by my friend @Deleted:

 

"Does anyone know how to download all the photos / images from a specific group in one go?"

 

I didn't.  But I figured out a way to do it, and I'd like to share it with you.

 

First, you'll need to get a developer token.  It has become very simple to do this in recent years.  I just wrote this article to help you through this process.  

 

Good, now you have your token.  Congratulations, a new world has opened up to you.  Anyway, here's what's next.

 

1.) Perform an export for the date range you're targeting.  I usually choose 1/1/2010 as a start date so that I get everything.  Do not include attachments; you'll get them individually.


2.) Copy files.csv to a different directory and open in Excel. You'll need that directory in step 7.)


3.) Sort by group_name.


4.) Delete all entries besides the ones for your target group.


5.) Save the script below as GetAttachments.ps1.


6.) Open the script in Notepad.


7.) Update with the correct target directories and your token.


8.) Run the script.

 

9.)  Let us know if it worked for you!  

 

# This will read a export files.csv file and go download all the files in that csv and put them in the directory you choose.
# You have to update the first three lines, token, pathofcsv, and pathofoutput according to your needs.  Everything else should just work.
# Make sure the paths actually exist or it will just error.
# © Tom Kretzmer August 2017.

 $token = "<your token>" 
 $pathofcsv = "C:\Data\Yammer\Powershell\Attachments\Files.csv"
 $pathofoutput = "C:\Data\Yammer\Powershell\Attachments\Admin"

# You shouldn't need to edit anything under this line.
 
 $Headers = @{ 
 "Accept" = "*/*" 
 "Authorization" = "Bearer "+$token 
 "accept-encoding" = "gzip" 
 "content-type"="application/json" 
 "content-length" = "2" 
 } 
 
#Get list of files to download. 
 $fileurls = import-csv $pathofcsv 
 
#Loop through everything in your list.
 foreach ($fileurl in $fileurls){ 
 
 $uri = $fileurl.download_url
 $filename =  $fileurl.name
 
 $ExportedFile = "$pathofoutput\$filename"
 
Write-Host $uri 
 
(Invoke-WebRequest -Uri $uri -Method Get -Headers $Headers -outfile $ExportedFile).content  
 
 } 

 

Note:  A "where" clause can be added to the script to eliminate the step of editing the csv, but I've found people are very comfortable editing CSVs but not as comfortable editing scripts.  This way you can use this method to go download in batch anything you want to download; just update your CSV and this thing will read it that CSV and download accordingly.

 

6 Replies
Hey Tom I have followed the instructions to the Run the script.. and..hold on.. how do you run the script? at which point you are ptrobably face planting but seriously.. I how do you run the script D'oH!

So let's say you saved the file GetAttachments.ps1 in this directory:  

 

C:\Data\Yammer\Powershell\Attachments

 

Go to the Windows screen and type "cmd"

 

A command window will open up.  Start PowerShell by typing powershell and hitting enter

 

Change directory to where your file is by typing this:

 

cd C:\Data\Yammer\Powershell\Attachments

 

Then, start the program by typing a period, then a slash, then the name of the patch file:

 

.\GetAttachments.ps1

 

PowerShell.jpg

 

 

 

 

Tom you are a marvel thank you soo much ;)

@Tom Kretzmer this was super helpful, thanks!

@Tom Kretzmer 

 

Hi

I have followed all the steps and when i executed script i got the below error. Please guide me.

=========================================================

Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument
that is not null or empty, and then try the command again.
At D:\Power\GetAttachments.ps1:34 char:25
+ (Invoke-WebRequest -Uri $uri -Method Get -Headers $Headers -outfile $ ...
+ ~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

===================================================

 

 

@prashanthdesai 

Hi,

I was able to execute the script successfully now but the agenda of separating the data group wise is defeated. The script after execution returned all the data files in one folder only. 

Basically, i want to separate the data per yammer groups but not all the data under one group. Please help on this regard.

 

Thanks for sharing this script.

 

Regards

Prashanth