Manage / Update Office 365 Video channel permissions from CSV using PowerShell

Featured image

Office 365 video has become a robust solution for Educational institutions and corporates to manage their study / training videos and present it to their users via a single portal. Earlier there was no better solution for video management and thus it was attracted by a majority of users. You will get 365 view about Office 365 video from this getting started blog ‘ Getting started with Office 365 video’.

As MSFT designed this portal in a self-service fashion, permissions for each channel is classified as Owners, Editors and Viewers). Assignment of these permissions to each channel became mandatory to provision the channels to users. Hence managing / updating permissions for each channel becomes tedious for channel admin and as always PowerShell helps here to manage this.

This script helps you to add or remove users in Office 365 Video Permissions(Owners, Editors and Viewers) in bulk through csv. This script requires to provide CSV file with the video channel url, user’s email-id, and the channel permissions. To get the URL for the Office 365 Video Channel refer this technet post.

Below is the format of the CSV file with required headers. Group with column value “true” adds to the member and with “false” removes the member from the group.

        ChannelUrl,UserEmail,Contributors,Creators,Viewers
        https://XXXX.sharepoint.com/portals/products, annew@XXXX.onmicrosoft.com, true, true, true
        https://XXXX.sharepoint.com/portals/marketing, alexd@XXXX.onmicrosoft.com, false, false, false
        https://XXXX.sharepoint.com/portals/products, alexd@XXXX.onmicrosoft.com, false, false, false
   
$UserName = "admin@XXXX.onmicrosoft.com" 
$Password = "XXXX" 
$filePath = "C:\Users\XXXX\Desktop\video-users.csv" 
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force 
Import-Csv $filePath | ForEach-Object{ 
    $SPOVideoChannelUrl = $_.ChannelUrl 
    $UserToAdd = $_.UserEmail 
     
    $UserCredential = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)    
 
    $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SPOVideoChannelUrl)  
    $ctx.Credentials = $UserCredential  
    $webSite = $ctx.Web 
    $ctx.Load($webSite) 
    $ctx.Load($webSite.SiteGroups) 
 
    $contributorsGrp = $webSite.SiteGroups.GetByName("Contributors") 
    $creatorsGrp = $webSite.SiteGroups.GetByName("Creators") 
    $viewersGrp = $webSite.SiteGroups.GetByName("Viewers") 
 
    $ctx.Load($contributorsGrp) 
    $ctx.Load($creatorsGrp) 
    $ctx.Load($viewersGrp) 
    $ctx.ExecuteQuery() 
 
    $user = $webSite.EnsureUser($UserToAdd) 
    $ctx.Load($user) 
    $ctx.ExecuteQuery() 
 
    if($_.Contributors -eq "true") 
    { 
        $temp1 = $contributorsGrp.Users.AddUser($user) 
        $ctx.Load($temp1) 
        $ctx.ExecuteQuery() 
    } 
    elseif($_.Contributors -eq "false") 
    { 
        try{ 
        $temp1 = $contributorsGrp.Users.Remove($user) 
        $ctx.ExecuteQuery() 
        }catch{} 
    } 
 
    if($_.Creators -eq "true") 
    { 
        $temp2 = $creatorsGrp.Users.AddUser($user) 
        $ctx.Load($temp2) 
        $ctx.ExecuteQuery() 
    } 
    elseif($_.Creators -eq "false") 
    { 
        try{ 
        $temp2 = $creatorsGrp.Users.Remove($user) 
        $ctx.ExecuteQuery() 
        }catch{} 
    } 
 
    if($_.Viewers -eq "true") 
    { 
        $temp3 = $viewersGrp.Users.AddUser($user) 
        $ctx.Load($temp3) 
        $ctx.ExecuteQuery() 
    } 
    elseif($_.Viewers -eq "false") 
    { 
        try{ 
        $temp3 = $viewersGrp.Users.Remove($user) 
        $ctx.ExecuteQuery() 
        }catch{} 
    } 
 
    $ctx.ExecuteQuery() 
 
    Write-Host "Processed $($UserToAdd) for $($SPOVideoChannelUrl)" -foregroundcolor Green  
}