Is it possible to change a SharePoint site's list of group owners in Powershell?
I had users populate a CSV with Title, Alias, and Owners headings corresponding to the SharePoint sites they needed created, after which I created them using the following script:
$AdminUrl = "https://tenant-admin.sharepoint.com/"
$RootUrl = "https://tenant.sharepoint.com/"
$CSVFileName = .\SiteCollections.csv
$sites = Import-Csv "$CSVFileName"
Connect-PnPOnline $AdminUrl -UseWebLogin
foreach ($site in $sites) {
[String[]]$siteOwners = $site.Owners.split(";")
New-PnPSite -Type TeamSite -Title $site.Title -Alias $site.Alias -Owners $siteOwners -Wait
}
After creating the sites however, I was informed that the site owners needed to be changed, as well as some of the site titles and URL's.
I was unable to add/remove members to the sites' owners group via Powershell, and when I decided to just remove all of the sites and recreate them, I got the error Remove-SPOSite : This site belongs to a Microsoft 365 group. To delete the site, you must delete the group. Attempting to remove the groups by the Microsoft 365 group name resulted in Remove-SPOSiteGroup : Group cannot be found.
Is there any way I can rectify the owners' group members, or otherwise remove them on mass to start again?
