I am trying to set groups Owner of a specific Sub-site using CSOM.
My site collection path is "https://mytenant.sharepoint.com/".
Sub-site path "https://mytenant.sharepoint.com/subsite".
First I wanna retrieve SharePoint Groups of my specific Sub-site but my code retrieve all Sub-sites groups of my collection site .
Here's my code :
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$siteURL = "https://mytenant.sharepoint.com/subsite"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)
$userId = "myID"
$pwd = Read-Host -Prompt "Enter password" -AsSecureString
$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)
$ctx.credentials = $creds
$web = $ctx.web
$groups = $web.SiteGroups
$ctx.Load($groups)
$ctx.ExecuteQuery()
foreach($group in $groups){
Write-Host "Site Group : " $group.Title
$ctx.ExecuteQuery()
}
Can anyone explain what I'm doing wrong ?