使用 PowerShell 从 SharePoint 中的 CSV 文件创建批量警报
要求:
在 SharePoint Web 应用程序的不同网站集中的一堆库上创建警报!
解决方案:识别并导出 CSV 文件中的网站和文档库名称列表,并使用此 PowerShell 脚本创建多个警报。
用于从 CSV 文件创建批量警报的 PowerShell 脚本:
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
}
这是我的 CSV 文件:
