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"]

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

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


Have fun using this!