magritton
3/23/2017 - 5:26 PM

Example of changing a list item without changing the modified by and date and without triggering the spitem event receiver.

Example of changing a list item without changing the modified by and date and without triggering the spitem event receiver.

#set the web url and the list name to work upon
$url = "https://xxx"
#$listName = "CATS Items"
$listName = "CATS 2015 Archive"

#Get the appropriate list from the web
$web = get-SPWeb $url
$list = $web.lists[$listName]

#$assembly = [Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint");
#$type = $assembly.GetType("Microsoft.SharePoint.SPEventManager");
#$prop = $type.GetProperty([string]"EventFiringDisabled",[System.Reflection.BindingFlags] ([System.Reflection.BindingFlags]::NonPublic -bor [System.Reflection.BindingFlags]::Static));
 
#$prop.SetValue($null, $true, $null); #Disable event firing
$cnt = 0
foreach($item in $list.Items)
{
	if($item["Department"] -eq "873" ) #-eq "374;#843"
	{
		#write-host "Updating..." + $item["ID"]
		#$item["Department"] = "800"
		#$item.SystemUpdate($false)
		$item["Department"]
		$cnt++
	}
}

#$prop.SetValue($null, $false, $null);#Enable event firing

write-host "done. $cnt updated"

$web.dispose()

$web = $null