SharePoint add users and Break Role Inheritance via powershell
# --------Input Parameters
$userName="scu\SP-MSBAnnouncementsMembers"
$siteURL="http://thesound/Dept/MBS"
$listName="Announcements"
$site=Get-SPSite $ siteURL
$web=$site.RootWeb
$list=$web.lists[$listName]
$collRoleDefinitions = $web.RoleDefinitions;
$collRoleAssignments = $list.RoleAssignments;
$user=$web.EnsureUser($userName);
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($user.LoginName, $user.Email, $user.Name, $user.Notes);
$collRoleDefinitionBindings = $roleAssignment.RoleDefinitionBindings;
$collRoleDefinitionBindings.Add($collRoleDefinitions["Contribute"]);
$collRoleAssignments.Add($roleAssignment);
$list.Update();
Add-PSSnapin Microsoft.SharePoint.Powershell
$web = Get-SPWeb http://portal.opwftg.com/sites/OPWSS/Teams/OPCO/OES
$account = $web.EnsureUser("opwftg\cin-all")
$role = $web.RoleDefinitions["Contribute"]
$list = $web.Lists["Customer Compalint Doc Library"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()
$list = $web.Lists["Customer Complaint Links"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()
$list = $web.Lists["Deviations"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()
$list = $web.Lists["RMA"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()
$web.Dispose()
Add-PSSnapin Microsoft.SharePoint.Powershell
$web = Get-SPWeb http://portal.opwftg.com/sites/OPWSS/Teams/OPCO/OES
$account = $web.EnsureUser("opwftg\cin-all")
$role = $web.RoleDefinitions["Contribute"]
$list = $web.Lists["Customer Complaint Anouncements"]
$list.BreakRoleInheritance($true)
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($account)
$assignment.RoleDefinitionBindings.Add($role)
$list.RoleAssignments.Add($assignment)
$list.Update()
$web.Dispose()