How to get a Video Thumbnail using PowerShell on SharePoint SE version?

Jean Paul Larach 36 Reputation points Microsoft Employee
2023-10-12T02:16:15.8233333+00:00

I have a SharePoint (Subscription Edition) document library that is hosting some videos I uploaded. How can I get the video thumbnails using PowerShell? Again, the SharePoint version I am targeting is the Subscription Edition so using Graph is not supported. Any idea how to do this with CSOM/PowerShell/Rest?

JP

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
Windows for business | Windows Server | User experience | PowerShell
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-10-13T06:07:34.14+00:00

    HI @Jean Paul Larach,

    One possible way to get the video thumbnails from a SharePoint document library using PowerShell is to use the SharePoint CSOM API.

    The CSOM API provides a method called GetFileByServerRelativeUrl that can be used to get a reference to a file in a document library.

    Then, you can use the ListVideoThumbnails method to get a collection of thumbnails for the video file. You can also specify the width and height of the thumbnails you want to retrieve.

    This is just a code template for your reference. For specific situations, you need to modify the code according to your scenario.

    Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll” 
    Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”
    
    $SiteUrl = “https://contoso.sharepoint.com/sites/videosite” $VideoFileUrl = “/sites/videosite/Shared Documents/MyVideo.mp4”
    
    $UserName = “******@contoso.com” $Password = “password”
    
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl) $Context.Credentials = $Credentials
    
    $VideoFile = $Context.Web.GetFileByServerRelativeUrl($VideoFileUrl) $Context.Load($VideoFile) $Context.ExecuteQuery()
    
    $Thumbnails = $VideoFile.ListVideoThumbnails(200, 200) # Specify the width and height of the thumbnails $Context.Load($Thumbnails) $Context.ExecuteQuery()
    
    foreach ($Thumbnail in $Thumbnails) {
     Write-Host $Thumbnail.ServerRelativeUrl 
    }
    $Context.Dispose()
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards

    Cheng Feng


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.