Jaa


Script to help with Site Deletion feature

Hello All,

I'm sure many of you know about the Site Deletion feature, if you don't please read here.  My customer was having some issues as users weren't responding to emails then they were complaining when sites were deleted.  They also realized later on that the feature doesn't look at SPWeb object (Sub Sites) so I wrote a quick script to help get around some of there concerns.

The script does the following:

  1. Reports to CSV on Url, CertificationDate (Last date confirmed), DeadWebNotificationCount (Emails sent)
  2. ConfirmUsage() on all Sites in whitelist
  3. Reviews LastItemModifiedDate for all subsites and ConfirmUsage() for all sites that have active subsites.

First thing to do is set the variables and I have 4 of them

$WebAppURLs = @("https://sp.weaver.ad","https://ecm.weaver.ad")
$SubWebAge = 39
$WhiteList = "C:\Temp\whitelist.txt"
$OutputFile = "C:\Temp\Output.csv"

The first variable sets which Web Applications you will interrogate, then we need to know how long subsites have to be inactive before we don't Confirm Usage for them, then come the white list which is a text file with Site Url's for all sites that we want to exclude from the Site Usage feature and the output file.

$SiteUrl = $_.Url
$CertDate = $_.CertificationDate
$NotificationCount = $_.DeadWebNotificationCount
Add-Content -Path $OutputFile -Value "$SiteUrl, $CertDate,$NotificationCount"
ForEach ($Site in $WhiteListSite) {
if($_.Url -eq $Site)
{
$_.ConfirmUsage() | Out-Null
}
}

Then for each Site collection we gather the Url, CertificationDate, and the DeadWebNotificationCount and save it to a csv file, we then compare the site url to the whitelist file and for each one we find we run ConfirmUsage() so that the owners never get emails and the site never will be deleted.

$Site | Get-SPWeb -Limit ALL | ForEach-Object {
$TodaysDate = Get-Date
$LastModifiedDate = $_.LastItemModifiedDate
$DateDifference = (New-TimeSpan –Start $LastModifiedDate –End $TodaysDate).Days
if($DateDifference -lt $SubWebAge)
{
$Site.ConfirmUsage() | Out-Null
}
}

Then lastly the script goes thru all sub sites and compares the LastItemModifiedDate to today() and if the difference is less then the variable $SubWebAge that means the sub site is active and we run ConfirmUsage() on the parent Site Collection.

You can find the full script here

Pax