Change SharePoint site group ownership; or remove list of sites and groups

Thomas Lu 41 Reputation points
2021-08-17T23:11:52.57+00:00

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?

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,745 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,389 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Elsie Lu_MSFT 9,771 Reputation points
    2021-08-18T07:02:55.23+00:00

    Hi @Thomas Lu , welcome to Q&A forum!

    Microsoft groups and SharePoint groups are two different groups. Microsoft 365 groups are used for collaboration between users, both inside and outside your company. With each Microsoft 365 group, members get a group email and shared workspace for conversations, files, and calendar events, Stream and a Planner:

    ======================================

    As an admin, you can manage Office 365 groups through Microsoft 365 admin center.

    Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com
    Expand Groups and Click on Groups in the left navigation.
    Select the Office 365 group to delete.
    In the details pane, click on the “Delete” button and confirm the delete group in Office 365.

    124165-35.jpg

    Reference:
    Manage a group in the Microsoft 365 admin center
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.


    If the answer is helpful, please click "Accept Answer" and upvote it.

    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.