SOLVED

Set-PnPGroup : Group cannot be found

Copper Contributor

Goal is to create a site collection level SharePoint group with 'Read' permissions, and apply this group to each sub-site. This group should contain several members.

My code is failing on:

Set-PnPGroup -Identity $glbMGRConts -Owner $OwnersGroup

... and says Group cannot be found. Not sure why, the group exists, and this line to set permissions to 'Read' works:

 Set-PnPGroupPermissions -Identity $glbMGRConts -AddRole "Read"

#

$varURL = "https://company.sharepoint.com/sites/Sandbox"
Connect-PnPOnline -Url $varURL -UseWebLogin
#Grab global owners group$OwnersGroup = Get-PnPGroup -AssociatedOwnerGroup

#Create name for group$glbMGRConts = "GlobalMGRs"
New-PnPGroup -Title $glbMGRConts

Add-PnPUserToGroup -LoginName user1@co.com -Identity $glbMGRConts
Add-PnPUserToGroup -LoginName user2@co.com -Identity $glbMGRConts Set-PnPGroupPermissions -Identity $glbMGRConts -AddRole "Read" Set-PnPGroup -Identity $glbMGRConts -Owner $OwnersGroup Function Get-Subsites() { $subwebs= Get-PnPSubWebs -Recurse foreach ($Subweb in $subwebs) { Set-PnPGroupPermissions -Identity $glbMGRConts -web $Subweb -AddRole Read } } Get-SubSites

 

1 Reply
best response confirmed by Chip Cooper (Copper Contributor)
Solution

@Chip Cooper  Hello.

As you got the object saved to $OwnersGroup Var

$OwnersGroup = Get-PnPGroup -AssociatedOwnerGroup 

 When you set the Owner you have to select the specific attribute that represents the Identity or any unique value inside $OwnersGroup variable. 

 

Set-PnPGroup -Identity $glbMGRConts -Owner $OwnersGroup.Title #Or any other unique identity attribute

Regards

Erick Moreno 

1 best response

Accepted Solutions
best response confirmed by Chip Cooper (Copper Contributor)
Solution

@Chip Cooper  Hello.

As you got the object saved to $OwnersGroup Var

$OwnersGroup = Get-PnPGroup -AssociatedOwnerGroup 

 When you set the Owner you have to select the specific attribute that represents the Identity or any unique value inside $OwnersGroup variable. 

 

Set-PnPGroup -Identity $glbMGRConts -Owner $OwnersGroup.Title #Or any other unique identity attribute

Regards

Erick Moreno 

View solution in original post