none
Constructor Not Found

    Question

  • Script works individually ran but when added to a bigger script it fails. Trying to figure this out. Can someone help?

    New Object A constructor was not found. Cannot find an appropriate constructor for type Microsoft.SharePoint.SPRoleAssignment

    Code

    Function AddGroupToSite ($web, $groupName, $permLevel) {

                    Write-Output “Adding $($groupName)…”

                    $account =  $Null

                    Foreach($grp in $web.Groups) {

                                    Write-Output “$account.Name”

                    If($grp -eq $groupName) {

                                    $account = $groupName

                                    Write-Output “Group found: $($account.name)”;

                                    Write-Output “In the if statement”

                                   

                    }

    }

                    $assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)

                    $role = $web.RoleDefinitions[$permLevel]

                    $assignment.RoleDefinitionBindings.Add($role);

                    $web.RoleAssignments.Add($assignment)

                    Write-Output “Completed Group Permissions Level Assignments”

    }


    Lewin Wanzer MCSE, MCDBA, MCTS (SQL 2005, 2010 Config, 2007 Config)


    Friday, April 21, 2017 3:07 AM

All replies

  • $account is not a string.  It must be an SPPrincipal.  You are using a string.


    \_(ツ)_/

    Friday, April 21, 2017 4:44 AM
    Moderator