Use PowerShell to set item permissions in bulk

Today I needed to set some permissions to >1000 items in a list. For some reason the Author of each items needed Read permissions. That was no longer the case on most items. I created a PowerShell script to do this:

#Load SharePoint Snap In
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$webUrl = "http://yourcoolsiteUrl"
$web = Get-SPWeb $webUrl
$list = $web.Lists["your cool list name"]
$PermissionLevel="Read"

foreach ($item in $list.items) {
	Write-Host $item.Title
	if($item.HasUniqueRoleAssignments -eq $False){
		$item.BreakRoleInheritance($True)
	}
	$userfield = New-Object Microsoft.SharePoint.SPFieldUserValue($web,$item["Author"].ToString());            
	$user=$userfield.User;

	$roleDefinition = $web.RoleDefinitions[$PermissionLevel]
	$roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
	$roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
	$item.RoleAssignments.Add($roleAssignment)
	$item.Update()
	Write-Host "Successfully added $PermissionLevel permission to $user. " -foregroundcolor Green

}
$web.Dispose()

Have fun using this!