Setting default associated group via PowerShell not working

In SPO we have a couple of sites that lack a default group for the “Allow members to share this site and individual files and folders”.

enter image description here

I’m trying to set a SharePoint security group named “OOTB Visitors” as the default group for this through PowerShell.

Through the GUI it’s easily done by going into the group choosing:

enter image description here

In PowerShell I found a method for the web named .CreateDefaultAssociatedGroups()

However, I can’t get it to work. I don’t get an error message but it also doesn’t change anything.

Any idea what I’m missing?

Here’s my code:

$  ctx = Get-PnPContext $  web.CreateDefaultAssociatedGroups('Owners', $  null, 'OOTB Visitors') $  web.Update() $  ctx.ExecuteQuery()