We are in the final stages of preparation for the long-overdue upgrade to SharePoint 2010. I have set up a preview site with a copy of the production SharePoint content database, and I want to notify all site owners that they should check out their sites for major problems. How to do? PowerShell? Absolutely!
Set-PSDebug -Strict
Add-PSSnapin -Name microsoft.SharePoint.PowerShell
[string] $waUrl = "https://sharepoint2010.uvm.edu"
[string] $SmtpServer = "smtp.uvm.edu"
[string] $From = "saa-ad@uvm.edu"
$allAdmins = @()
[string] $subjTemplate = 'Pending Upgrade for your site -siteURL-'
[string] $bodyTemplate = @"
Message Body Goes Here.
Use the string -siteURL- in the body where you want the user's site address to appear.
"@
$wa = Get-SPWebApplication -Identity $waUrl
foreach ($site in $wa.sites) {
#Write-Host "Working with site: " + $site.url
$siteAdmins = @()
$siteAdmins = $site.RootWeb.SiteAdministrators
ForEach ($admin in $siteAdmins) {
#Write-Host "Adding Admin: " + $admin.UserLogin
[string]$a = $($admin.UserLogin).Replace("CAMPUS\","")
[string]$a = $a.replace(".adm","")
[string]$a = $a.replace("-admin","")
[string]$a = $a.replace("admin-","")
if ($a -notmatch "sa_|\\system") { $allAdmins += , @($a; [string]$site.Url) }
}
$site.Dispose()
}
$allAdmins = $allAdmins | Sort-Object -Unique
#$allAdmins = $allAdmins | ? {$_[0] -match "jgm"} | Select-Object -Last 4
foreach ($admin in $allAdmins) {
[string] $to = $admin[0] + "@uvm.edu"
[string] $siteUrl = $admin[1]
[string] $subj = $subjTemplate.Replace("-siteURL-",$siteUrl)
[string] $body = $bodyTemplate.Replace("-siteURL-",$siteUrl)
Send-MailMessage -To $to -From $From -SmtpServer $SmtpServer -Subject $subj -BodyAsHtml $body
}