Has anyone successfully used PS to create groups and assign a owner (another SP group not a domain user). The scripts I've found online, I can't get them to work. Just wondering if anybody has any working scripts to share. Preferable create from csv or txt so I can create a template.

2 Answers 2


This is something we built in-house:

function Add-SPGroup {
    Use Add-SPGroup to create a SharePoint Group.
    This function uses the Add() method of a SharePoint RoleAssignments property in an SPWeb to create a SharePoint Group.
    Add-SPGroup -webUrl "http://sharepoint.local" `
                -groupName "Test Group" `
                -description "My Group" `
                -ownerName "DOMAIN\userlogin" `
                -defaultMemberName "DOMAIN\userlogin" `
                -membership "DOMAIN\userlogin, DOMAIN\userlogin2"`

try {
    $codeLocation = "Opening web and checking group does not already exist."
    $web = Get-SPWeb $webUrl;
    $spGroup = $web.SiteGroups[$groupName];

    if ($spGroup -ne $null) {
        Write-Warning "Group $groupName already exists!";  
        return $spGroup; 
    $codeLocation = "Setting owner/member details.";
    $owner = $web.EnsureUser($ownerName);
    $member = $web.EnsureUser($defaultMemberName);

    $codeLocation = "Creating group.";
    $web.SiteGroups.Add($groupName, $owner, $member, $description);
    $spGroup = $web.SiteGroups[$groupName];

    $codeLocation = "Adding users to Group"
    $usersToAdd = $membership.split(",");
    foreach($user in $usersToAdd) {
        $ensuredUser = $web.EnsureUser($user.trim());

    return $spGroup;
catch {
    Write-Warning $codeLocation;
    Write-Error $Error[0];
} }

Hope this helps


I have a custom function adapted from this StackOverflow question. For whatever reason, the group owner is not settable if you are using the New-SPOSiteGroup commandlet.

Function Set-GroupOwner{
        Sets the specified GroupOwner, a Sharepoint group, as the owner of the specified Group
        When creating groups with New-SPOSiteGroup, there is no way to set the group owner. While -Owner is a parameter of Set-SPOSiteGroup,
        it does not appear to be settable. This function solves that problem.
        .PARAMETER SiteUrl
        The Url of the subsite the group needs permission to.
        .PARAMETER GroupToUpdate
        The name of the group that needs updated.
        .PARAMETER GroupOwner
        The SharePoint group that should be listed as the group owner.
        This example sets the Eric Playground Owners group as the group owner of A Test Subsite Members
        Set-GroupOwner -SiteUrl "https://tenant.sharepoint.com/teams/eric" -GroupToUpdate "A Test Subsite Members" -GroupOwner "Eric Playground Owners"
        Adapted from https://stackoverflow.com/a/25654742/318776
        [Parameter(Mandatory=$true,HelpMessage="The URL of the site collection",Position=0)][ValidateNotNull()]

        [Parameter(Mandatory=$true,HelpMessage="The group that needs updated",Position=1)][ValidateNotNull()]

        [Parameter(Mandatory=$true,HelpMessage="The desired group owner",Position=2)][ValidateNotNull()]

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)

    $owner = $context.Web.SiteGroups.GetByName($GroupOwner)
    $group = $context.Web.SiteGroups.GetByName($GroupToUpdate)

    $group.Owner = $owner


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.