I need help please. I’m trying to copy a role definition/name in SharePoint 2010 Powershell.
The below is only a piece of my script, but I have to find '$SearchUser" and wherever it lives (webs, lists, groups), I need to add "$account" and copy permissions
from '$SearchUser" . We are doing this to limit certain users from access our farm (by adding a new AD domain that does not contain these users, then deleting the old domain). Every time I run it, it seems to mess up on this line: $role = $web.RoleDefinitions.[$newRoleDef]. It is acting like the $newRoleDef is null, but it is not. When I outputfile the $newRoleDef, it has values, such as Read, Contribute.
foreach($Web in $Site.AllWebs)
{
if($Web.HasUniqueRoleAssignments -eq $True)
{
foreach($WebRoleAssignment in $Web.RoleAssignments )
{
if($WebRoleAssignment.Member.userlogin)
{
if($WebRoleAssignment.Member.LoginName -eq $SearchUser)
$WebUserPermissions=@()
foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings)
{
$newRoleDef = $RoleDefinition.Name
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$role = $web.RoleDefinitions.[$newRoleDef]
$assignment.RoleDefinitionBindings.Add($role)
$_.RoleAssignments.Add($assignment)