TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
PowerShell Script to Remove Event receiver from Library
Ketak Bhalsing
May 20
2016
Code
4.5
k
0
0
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
#check to see
if
the PowerShell Snapin
is
added
if
((Get - PSSnapin | Where
{
$_.Name - eq
"Microsoft.SharePoint.PowerShell"
}) - eq $
null
)
{
Add - PSSnapin Microsoft.SharePoint.PowerShell;
}
##SharePoint DLL
[
void
][System.Reflection.Assembly]::LoadWithPartialName(
"Microsoft.SharePoint"
)
function RemoveEventReceiver($List, $EventReceiverId)
{
$eventReceivers = $List.EventReceivers | Where
{
$_.Id - eq $EventReceiverId
}
if
($eventReceivers)
{
foreach
($receiver
in
$eventReceivers)
{
Write - Host
"Deleting Event Receiver from "
$List.RootFolder.ServerRelativeUrl - ForegroundColor Yellow
$receiver.Delete()
Write - Host Deleted
event
receiver successfully. - ForegroundColor Green
}
}
else
{
Write - Host No Event Receivers on List with id $EventReceiverId present - ForegroundColor Yellow
}
}
write - host
"Please Enter Site collection url"
- foregroundcolor Yellow
$sourceSiteURL = Read - Host
write - host
"Please Enter Event Receiver Id"
- foregroundcolor Yellow
$Id = Read - Host
write - host
"Please Enter Document Library Title"
- foregroundcolor Yellow
$docLibrary = Read - Host
$siteColl = Get - SPSite $sourceSiteURL - ErrorAction silentlycontinue
if
($siteColl - ne $
null
)
{
$spweb = $siteColl.OpenWeb()
$TestList = $spweb.Lists[$docLibrary]
if
($TestList - ne $
null
)
{
Write - Host List found. - foregroundcolor Yellow
RemoveEventReceiver $TestList $Id
}
}
PowerShell
SharePoint
Event Receiver