Add Owner to SharePoint Online List PowerShell

This script uses SharePoint Client Side Object Model to Add Owner to selected SharePoint Online Libraries and Lists.  You need to install the latest SharePoint Online Client Components from Github or download them from Microsoft download center.  You can change the script to only find list by title and then add the owner.  The script creates the required objects and then add the User as owner. 

$User = “”
#$User = Read-host “Please enter Office365 Admin User name “
$Creds = Get-Credential

Connect-SPOService -Url -Credential $Creds
$site = Get-SPOSite

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’

#Get the Client Context and Bind the Site Collection
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($site.Url)

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Creds.UserName , $Creds.Password)
$ctx.Credentials = $credentials

#Fetch the users in Site Collection

$Web = $ctx.Web;
$Lists = $Web.Lists

$SAPLists = $Lists | ?{$_.Title -Like “SAP Data Quality Review*” } | Select Title
$SAPLists | Select Title

foreach($alist in $SAPLists)

   Write-Host $alist.Title
  $OwnersGroupTitle = “Site Owners”
  $OwnerGroup = $Web.SiteGroups.GetByName($OwnersGroupTitle)

  $FullControl = $web.RoleDefinitions.GetByName(“Full Control”)
  # Create a role assignment and apply the ‘read’ role.
  $roleAssignment = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($ctx)

  $SelectedList = $Web.Lists.GetByTitle($alist.Title)

Script is also available below

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s