Sunday, June 12, 2016

Create Bulk Alerts from CSV File in SharePoint using PowerShell

Requirement: Create alerts on bunch of libraries in different site collections of a SharePoint Web application!

Solution: Identified and exported list of Sites and Document Library names in the CSV file and used this PowerShell script to create multiple alerts.

PowerShell script to crate bulk alerts from CSV File:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Function to Create alert on Given List to given users
Function Create-Alert([Microsoft.SharePoint.SPList]$List,[Microsoft.SharePoint.SPUser]$User)
{
    $newAlert = $user.Alerts.Add()
    $newAlert.Title = "Minitoring Alert for: "+$List.Title
    $newAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::List
    $newAlert.List = $List
    $newAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email
    $newAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add
    $newAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate
    $newAlert.Update()
}

#Configuration parameters
$CSVPath= "C:\Alerts.csv"  
$UserAccount= "Crescent\Salaudeen" 
 
#Get the CSV Data
$CSVData = Import-CSV -path $CSVPath

#Iterate through each Row in the CSV
foreach ($row in $CSVData) 
{
    Write-host Creating Alerts on $Row.URL, Library: $Row.LibraryName
    #Get the Web and List
    $Web = Get-SPWeb $Row.URL.TRIM()
    $List = $Web.Lists[$Row.LibraryName.Trim()]  
    $user = $web.EnsureUser($UserAccount)
    
    #Call the function to create Alert
    Create-Alert $List $User    
}     
Here is my CSV File:
Create Bulk Alerts from CSV File in SharePoint using PowerShell



You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.
*Sponsored


Check out these SharePoint products:

2 comments :

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...