Archive

Archive for May, 2016

SharePoint 2013: Exception while creating default associated groups through PowerShell

While new site collection provisioned default security groups been provisioned when we create it from central administration but not when the site collection was created using script. For that we need to call a function ‘CreateDefaultAssociatedGroups’. This method actually created default associated group example member, Owner and Visitor group and add the group owner as the first parameter provided to the method call.

When I tried it some cases it worked and in some cases I was getting error “Exception calling “CreateDefaultAssociatedGroups” with “3” argument(s): “User cannot be found”

While analyzing the issue the issue I found that I am passing only first mandatory parameter as the user logon name of the group owner. Like –

$sps_web.CreateDefaultAssociatedGroups("MyDomian\spadmin","","");

And then I was getting error Exception calling “CreateDefaultAssociatedGroups” with “3” argument(s): “User cannot be found.” And the default groups are not getting added.

Further analysis concluded that the user I was passing as group owner was not getting added and hence the exception is thrown.

We have used EnsureUser before calling CreateDefaultAssociatedGroups function to make sure that before the call user should be available in user information list like –

$sps_web.EnsureUser("MyDomian\spadmin");
$sps_web.CreateDefaultAssociatedGroups("MyDomian\spadmin","","");
Advertisements