Hello,
I need to basically find everyplace 'ADUser1' exists and then add a new 'ADUser2' with the same permissions as the first group.
I have created a script that runs through an entire web app and finds everyplace the AD account is directly given access to and access via a group. I then need to add the new user and assign the permissions from the first ADUser, copy them. Below is not the entire script, just where I'm trying to add the new user. The rest of the script works fine to find the first user. I'm stuck with this part: $role = $_.RoleDefinitions[$newRoleDef]. I get an error that I can call a method on a null valued experssion.. I guess I don't know how to specify to copy the role from the first user, and use it to set the new user?
#Get the Permissions assigned to user
$WebUserPermissions=@()
foreach ($RoleDefinition in $WebRoleAssignment.RoleDefinitionBindings)
{
$WebUserPermissions += $RoleDefinition.Name +";"
$newRoleDef = $RoleDefinition.Name
}
#write-host "with these permissions: " $WebUserPermissions
#Send the Data to Log file
"$($Web.Url) `t Site `t $($Web.Title)`t Direct Permission `t $($WebUserPermissions)" | Out-File C:\Apps\Scripts\Logs\UserAccessReport.csv -Append
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$role = $_.RoleDefinitions[$newRoleDef]
$assignment.RoleDefinitionBindings.Add($role)
$_.RoleAssignments.Add($assignment)
}
}