Thursday, October 31, 2013

SharePoint & PowerShell: List all alerts (on document libraries, lists) in a site

As a site collection administrator, I find it extremely tedious to go to Site Actions - Site Settings, click on User Alers, and display alerts one by one. Here's a PowerShell script to get the information needed~!

Let's say you have a subsite with the URL http://sharepoint/subsite1

Launch SharePoint 2010 Management Shell and run this script (copy and paste the following, and save it as .ps1).

## Load the website
     $web = Get-SPWeb "http://sharepoint/subsite1/" 
     $resultSet = @() 
         foreach ($alert in $web.Alerts){ 
             $URL = $web.URL + "/" + $alert.ListUrl 
             $result = New-Object PSObject 
             $result | Add-Member -type NoteProperty -name "Title" -value $alert.Title 
             $result | Add-Member -type NoteProperty -name "URL" -value $URL 
             $result | Add-Member -type NoteProperty -name "Alert Type" -value $alert.AlertType 
             $result | Add-Member -type NoteProperty -name "User" -value $alert.User 
             $resultSet += $result 
        } 

## Best practice: dispose when done
    $web.Dispose() 

## Display the result
    $resultsSet 

## To export the result
    $resultSet | Export-Csv "Output.csv"

Tuesday, October 1, 2013

PowerShell script to Monitor and Auto-expand SharePoint site collection quota

Get-SPSite -Limit ALL | 
    Where { $_.Url -like "*/teamsite/*" -and [int]($_.Usage.Storage/1MB) -gt [int](($_.Quota).StorageWarningLevel/1MB) } |
    ForEach-Object {
 $maxSize = ($_.Quota).StorageMaximumLevel + (5000*1MB)
 $maxWarning = $maxSize - (200*1MB)
        Set-SPSite -Identity $_.Url -MaxSize $maxSize -WarningSize $maxWarning
    }

This script will retrieve all Sharepoint site objects where there is a "/teamsite/" found in the URL, and where the current usage has exceeded the user warning level.
It will automatically increment 5 GB of storage quota and update the warning level as well.

However, there are situations where some sites have unlimited quota. In this case, you will have to modify the script slightly to include an additional condition:
Where { $_.Url -like "*/teamsite/*" -and [int](($_.Quota).StorageWarningLevel/1MB) -gt 0 -and [int]($_.Usage.Storage/1MB) -gt [int](($_.Quota).StorageWarningLevel/1MB) }
Related Posts Plugin for WordPress, Blogger...