Get List of Videos from Microsoft Stream

Get List of Videos from Microsoft Stream

Getting a list of videos from Stream, so that you can look to migrate them or just to see what is there is hard. There is not much information on the Web about how to go about doing this, especially on large tenants.

My colleague Conrad has been working with the script from Powershell Script to list A LL videos in your 365 Stream environment – Microsoft Tech Community and has helped improve that script. He set me a challenge to remove the manual tasks like getting the data center location and copying/pasting URLs…

At first I was a bit daunted since obviously the author Dorje McKinnon would have spent time researching how this could be done. Anyway I set to work. At first I tried to see if I could get an access token from graph and then use that, but in the end Bing (or more to the point Google) came to the rescue. I found a script Export a csv report on all Microsoft Stream videos | PnP Samples. This looked very promising when looking through the code, unfortunately it didn’t work…

However, the idea was sound, so I played with some of the internal logic to try to work out what was broken. The key piece I looked at was

            function CaptureToken() { 
                var tenantInfo = new Object();
                tenantInfo.AccessToken =''
                if (sessionInfo != undefined) {
                    tenantInfo = new Object();
                    tenantInfo.AccessToken = sessionInfo.AccessToken;
                    tenantInfo.TenantId = sessionInfo.UserClaim.TenantId;
                    tenantInfo.ApiGatewayUri  =sessionInfo.ApiGatewayUri;
                    return (JSON.stringify(tenantInfo));
                return (JSON.stringify(tenantInfo));

This was failing, and turning on the javascript warnings in the browser and fixing some syntax issues, it turned out that MS must have removed the JSON object from their pages. Never fear though since we only have a simple object to create. I updated the code to

        function CaptureToken() { 
            if( typeof sessionInfo === undefined ) {
                return '';
            } else {
                outputString = '{';
                outputString += '"AccessToken":"' + sessionInfo.AccessToken + '",';
                outputString += '"TenantId":"' + sessionInfo.UserClaim.TenantId + '",';
                outputString += '"ApiGatewayUri":"' + sessionInfo.ApiGatewayUri + '",';
                outputString += '"ApiGatewayVersion":"' + sessionInfo.ApiGatewayVersion + '"';
                outputString += '}';

                return outputString;

and I managed to get an access token returned! After that it was plain sailing, well relatively. I tidied up the rest of the code (since every developer has their own style) and removed some unnecessary pieces.

In the end the script runs well and no more looking for data centers or copying/pasting urls. Instead you get the output as objects, or if you specify a csv filename then it will export to that csv. Some useful bits of info include the URL where that video is at, it’s size, duration, height, width, count of likes, etc.

You do need to be a Stream admin or Global Admin so that we can grab the videos in admin mode, but even for a large tenant the process takes only seconds to run!

Thanks to Dorte and Rodrigo for the original scripts and some of the ideas, and thanks to Conrad for setting the challenge!

As always the script is provided on an as is basis, while it does only issue get requests it still always pays to test the script in a non production environment first.