Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Bounty
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
PowerShell Script to Remove Event receiver from Library
WhatsApp
Ketak Bhalsing
May 20
2016
4.6
k
0
0
#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
Up Next
PowerShell Script to Remove Event receiver from Library