Monday, June 18, 2012

How to delete the deployed Event Receiver in Sharepoint server 2010 - PowerShell

I took it from this article

$spWeb = Get-SPWeb -Identity http://contoso.com

$spList = $spWeb.Lists["My List Name"]
$eventsCount = $spList.EventReceivers.Count
$assembly = "Project.Name.Class, Version=1.0.0.0, Culture=neutral, PublicKeyToken=11111111111"
$class = "Namespace.MyClass.ClassName"
$type = 10002
$name = "My Event Name"
for ($i = 0; $i -lt $eventsCount; $i+=1)
{
if ($spList.EventReceivers[$i].Assembly -eq
$assembly
-and
$spList.EventReceivers[$i].Class -eq $class
-and
$spList.EventReceivers[$i].Type -eq $type
-and $spList.EventReceivers[$i].Name -eq
$Name)
{
$spList.EventReceivers[$i].Delete()
}
}
$spList.Update()

No comments:

Post a Comment