1. 程式人生 > >How to Operate SharePoint User Alerts with PowerShell

How to Operate SharePoint User Alerts with PowerShell

When you migrate list or site, the user alerts in the site will not be migrated together with the content. Below content can help you to do this task. But please take care of it, if you operate it on Prod environment.  

Enable or disable alerts for Web application

## To enable alerts for Web application
$SPwebapp=Get-SPWebApplication "http://SharePointSite.com" $SPwebapp.AlertsEnabled = $true $SPwebapp.Update() # To Disable alerts for a Web application $SPwebapp.AlertsEnabled = $false $SPwebapp.Update()

Create Alert in SharePoint using PowerShell

##### Create an New alert for an user #########
$SPsite = Get-SPSite "http://SharePointSite.com" $SPweb=$SPsite.Rootweb $SPlist=$SPweb.lists["Shared documents"] $SPuser = $SPweb.EnsureUser('Domain\Salaudeen') $SPnewAlert = $SPuser.Alerts.Add() $SPnewAlert.Title = "My Custom Alert" $SPnewAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::List
$SPnewAlert.List = $SPlist $SPnewAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email $SPnewAlert.EventType = [Microsoft.SharePoint.SPEventType]::Add $SPnewAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate $SPnewAlert.Update() $SPweb.Dispose() $SPSite.Dispose()

Get all Alerts for an user in SharePoint with PowerShell

##### Display All alerts for a Particular List ########

$SPWeb = Get-SPWeb "http://SharePointSite.com"

#Relative URL of list/document library. For lists "Lists/Tasks"

$SPListURL = "Shared Documents" 

foreach($alert in $SPWeb.Alerts)

{

    if($alert.ListUrl -eq $SPListUrl)

    {           

            "User Name    - " + $alert.User.Name

            "Title        - " + $alert.Title

            "Frequency    - " + $alert.AlertFrequency

            "Delivery Via - " + $alert.DeliveryChannels

            "Change Type  - " + $alert.eventtype

            Write-Host "=================================="

    }

}

$SPweb.Dispose()

Create Alerts for All users in a Group

##### Set alerts for all users in the SharePoint Group ######

$SPweb = Get-SPWeb "http://SharePointSite.com"

$SPgroup = $SPweb.Groups["SharePoint Owners"]

$SPlist = $SPweb.Lists["Shared Documents"]

foreach ($SPuser in $SPgroup.Users){

     $alert = $SPuser.Alerts.Add()

     $alert.Title = "My Alert"

     $alert.AlertType = [Microsoft.SharePoint.SPAlertType]::List

     $alert.List = $SPlist

     $alert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::Email

     $alert.EventType = [Microsoft.SharePoint.SPEventType]::Add

     $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Immediate

     $alert.Update()

}

$SPweb.Dispose()

Update SharePoint Alerts using PowerShell

#####  Making Changes in Existing Alerts ########

$SPsite = Get-SPSite "http://SharePointSite.com"

$SPweb=$SPsite.RootWeb

$SPuser=$SPweb.EnsureUser('Domain\Salaudeen')

$SPalertCollection=$SPuser.Alerts

foreach($alert in $SPalertCollection)

{

  $alert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::Daily

  $alert.Update()

} 

Get Alerts for a Particular User

##### Get alerts for a particular user #########

$SPsite = Get-SPSite "http://SharePointSite.com"

$SPweb=$SPsite.RootWeb

$SPuser=$SPweb.EnsureUser('Domain\Salaudeen')

$SPalertCollection=$SPuser.Alerts

foreach($alert in $SPalertCollection)

{

 write-host -f Green $alert.Title

}

Find All Alerts of an User in Entire Site collection

##### Get the Alerts of Entire Site collection #####

$SPsiteCollection = Get-SPSite "http://SharePointSite.com"


# Iterate through all Webs in the Site Collection

foreach($SPweb in $SPsiteCollection.AllWebs) 

 {

   foreach($alert in $SPweb.Alerts)

    {

        Write-Host "Alerts List :" $alert.ListUrl

    Write-Host "Alerts Title :" $alert.title

    write-host "Subscribed User: " $alert.user

     }

 }

Delete All SharePoint alerts from a List using powershell

##### Delete All alerts for a specific List #####

$SPweb = Get-SPWeb "http://SharePointSite.com"

$SPlist = $SPweb.lists["Shared Documents"]

$IDS = ""

foreach($alert in $spweb.alerts)

{

    if($alert.ListID -eq $SPlist.ID)

    {

    $IDS += $alert.ID.tostring() + "|"

    }

    write-host -nonewline "*"

}

write-host "deleting..."

foreach($s in $IDS.Split("|"))

{

write-host -nonewline "*"

$spweb.alerts.delete([GUID]$s)

}

Delete user alerts in SharePoint 2010 with PowerShell

##### Remove all alerts for specific user from a Web Application #####

$SPwebApp = Get-SPWebApplication "http://SharePointSite.com"

$SpecificUser = "Domain\Salaudeen"

foreach ($SPsite in $SPwebApp.Sites)

    {

        # get the collection of webs

        foreach($SPweb in $SPsite.AllWebs)

        {

            $alerts = $SPweb.Alerts

            # if 1 or more alerts for a particular user, Make a note of them by copying their ID to an Array

            if ($alerts.Count -gt 0)

            {

                $myalerts = @()

                foreach ($alert in $alerts)

                {

                if ($alert.User -like $SpecificUser)

                {

                    $myalerts += $alert

                }

            }

            ### now we have alerts for this site, we can delete them

            foreach ($alertdel in $myalerts)

            {

                $alerts.Delete($alertdel.ID)

                write-host $alertdel.ID

            }

        }

    }

}

To delete all alerts:

$SPweb.Alerts| foreach-object {$web.Alerts.Delete($_.Id)}

Filter the alerts for a single list:

#For for e.g. http://SharePoint.com/site/Assets"
$SPweb.Alerts| where-object {$_.ListUrl -like "Assets"} 

Find all the Alerts for a specific user across the web:

# ? is the alias for where-object cmdlet
$web.Alerts | ? {$_.UserId -like "Domain\Salaudeen"}

Get all the alerts for a user across the entire site collection:

$site.AllWebs | select -expand Alerts | ? {$_.UserId -like "Domain\Salaudeen"

Export User Alerts

$site = Get-SPSite "http://2013portal"

$alertResultsCollection = @()

foreach ($web in $site.AllWebs) {

foreach ($alert in $web.Alerts){

$alertURL = $web.URL + "/" + $alert.ListUrl

$alertResult = New-Object PSObject

$alertResult |Add-Member -type NoteProperty -name "WebUrl" -Value $web.Url

$alertResult | Add-Member -type NoteProperty -name "ListURL" -value $alertURL

$alertResult | Add-Member -type NoteProperty -name "AlertTitle" -value $alert.Title

$alertResult | Add-Member -type NoteProperty -name "ListUrl" -value $alert.ListUrl

$alertResult | Add-Member -type NoteProperty -name "List" -value $alert.List

$alertResult | Add-Member -type NoteProperty -name "DeliveryChannel" -value $alert.DeliveryChannels

$alertResult | Add-Member -type NoteProperty -name "AlertType" -value $alert.AlertType

$alertResult | Add-Member -type NoteProperty -name "EventType" -value $alert.EventType

$alertResult | Add-Member -type NoteProperty -name "Frequency" -value $alert.AlertFrequency

$alertResult | Add-Member -type NoteProperty -name "AlertTime" -value $alert.AlertTime

$alertResult | Add-Member -type NoteProperty -name "SubscribedUser" -value $alert.User

$alertResultsCollection += $alertResult

}

}

$site.Dispose()

$alertResultsCollection

#Export to CSV

$alertResultsCollection | Export-CSV C:\Users\sp2013_farm_admin\Desktop\Alerts.csv

Import User Alerts

Import-Csv C:\Users\sp2013_farm_admin\Desktop\Alerts.csv |ForEach-Object{

$webUrl=$_.WebUrl

$listTitle=$_.List

$alertTitle=$_.AlertTitle

$subscribedUser=$_.SubscribedUser

$alertType=$_.AlertType

$deliveryChannel=$_.DeliveryChannel

$eventType=$_.EventType

$frequency=$_.Frequency

 

$web=Get-SPWeb $webUrl

$list=$web.Lists.TryGetList($listTitle)

$user = $web.EnsureUser($subscribedUser)

$newAlert = $user.Alerts.Add()

$newAlert.Title = $alertTitle

$newAlert.AlertType=[Microsoft.SharePoint.SPAlertType]::$alertType

$newAlert.List = $list

$newAlert.DeliveryChannels = [Microsoft.SharePoint.SPAlertDeliveryChannels]::$deliveryChannel

$newAlert.EventType = [Microsoft.SharePoint.SPEventType]::$eventType

$newAlert.AlertFrequency = [Microsoft.SharePoint.SPAlertFrequency]::$frequency

if($frequency -ne "Immediate"){

$AlertTime=$_.AlertTime

$newAlert.AlertTime=$AlertTime

}

$newAlert.Update()

} 

相關推薦

How to Operate SharePoint User Alerts with PowerShell

When you migrate list or site, the user alerts in the site will not be migrated together with the content. Below content can help you to do this task. But

question 002: dev c++ 當中如何調整字體大小?How to get the first program with C++? c++屬於什麽軟件?

space 什麽 pil get ctrl+鼠標 iostream 系統 using clu 方法:按住ctrl+鼠標滑輪滾動 c++屬於系統軟件還是應用軟件? 說哪個都不對,編譯之前屬於應用軟件,after compile ,it belongs to system so

How To Obtain Reliable Concrete Mixer With Pump Machines

There are numerous easy methods for getting excellent deals on concrete mixers with pumps. You might basically be taking a look at local companies

How to train Neural Network faster with optimizers?

from:https://towardsdatascience.com/how-to-train-neural-network-faster-with-optimizers-d297730b3713 AsI worked on the last article, I had the o

How to solve peer dependancy problem with angular---quickstart 提示npm ERR! argv

學習AngularJS 5 MIN QUICKSTART的Step 1:Create and configure the project的第三小步(c)Install packages時提示如下圖所示錯誤 QUICRSTAR 解決方法為 在執行命令的當前目錄下執行  np

How To Create Android Swipe Views With Tabs

Android swipe views provide lateral navigation between sibling screens such as tabs with a horizontal finger gesture (a pattern sometimes known as horiz

[iOS] How to properly dismiss modal viewcontroller with completion handler

有引數要傳給 dismiss 的 completion 要怎麼寫? Pretty easy, pass funcToCall() as a completion parameter (important note – I’m using curly braces here): viewController.

How to make HTTP Post request with JSON body in Swift

Try this, // prepare json data let json: [String: Any] = ["title": "ABC", "dict": ["1":"First", "2":"Second"]] let jsonDat

How to Build Serverless Vue Applications with AWS Amplify

You can also implement serverless AWS AppSync GraphQL APIs, Lambda functions, analytics, hosting, VR / AR scenes & more using the Amplify CLI & lib

How to Evade Expensive Phishing Filters with One Simple Trick

How to Evade Expensive Phishing Filters with One Simple TrickOne in three top-tier and mid-tier Australian law firms are susceptible to a cyber threat call

How to create a new business with AI?

Artificial intelligence is about to sweep massively in companies because it is a major element of digital transformation. Automation of low value-added tas

How to create interactive map plots with Plotly

Note: to do something like what I am about to describe, you will need an account with plotly as well as mapbox. Particularly because you will need an acces

how to run all Butler tools with a single command

The beauty of Docker — how to run all Butler tools with a single commandDocker is great.Docker is one of those tools that have the potential to fundamental

Command Magicks: How to Manipulate Files and Strings with the Console

Command Magicks: How to Manipulate Files and Strings with the ConsoleProgramming will make you be amazed by the Cosmos. Source: Pixabay.As developers, ther

How to write Epic Unit Tests with TypeScript, Jest, Redux and RxJS 6

How to write Epic Unit Tests with TypeScript, Jest, Redux and RxJS 6When we attempt to create some test lines for testing Epics with Redux, the task seems

[Tutorial, Part 1] How to develop Go gRPC microservice with HTTP/REST endpoint, middleware…

[Tutorial, Part 1] How to develop Go gRPC microservice with HTTP/REST endpoint, middleware, Kubernetes deployment, etc.There are a lot of article how to cr

How to Delete using INNER JOIN with SQL Server?

 https://stackoverflow.com/questions/16481379/how-to-delete-using-inner-join-with-sql-server You need to specify what table you are deleting f

How to Evaluate Machine Learning Algorithms with R

Tweet Share Share Google Plus What algorithm should you use on your dataset? This is the most co

How to Load Data in Python with Scikit

Tweet Share Share Google Plus Before you can build machine learning models, you need to load you

How to Get Good Results Fast with Deep Learning for Time Series Forecasting

Tweet Share Share Google Plus 3 Strategies to Design Experiments and Manage Complexity on Your P