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

Jean Paul Larach 31 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

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,300 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,810 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,597 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,329 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ChengFeng - MSFT 5,020 Reputation points Microsoft Vendor
    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 = “user@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