SharePoint 2010 FBA Powershell Warmup Script [quick and dirty]

I was browsing around for for a quick and dirty SharePoint 2010 warmup script for Powershell the other day, and found quite a few – however, all would fail for me.

See, the environment i’m running is a FBA (or rather AD + ADFS, multiple domains, no trust) environment and the scripts i found would all throw a 403 Forbidden error.

Figured quickly that this was of course caused by the WebClient call that most scripts utilised, so to overcome this obstacle i changed the WebClient call out with a WebRequest call and added the all-important UserAgent (this is the reason you’d get the 403 Forbidden error btw).

So, quick and dirty solution…still some stuff to do on it, such as ensure that the timeout error can be handled – but that’s for another day.

if (( Get-PSSnapin -Name “Microsoft.SharePoint.Powershell” -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin Microsoft.SharePoint.Powershell

function WarmupSite() {

start-sleep 1

$request = [System.Net.WebRequest]::Create($Web.Url)
$request.AllowAutoRedirect = $false
$request.proxy = [System.Net.WebRequest]::DefaultWebProxy

$request.Credentials = $NetworkCred
$request.ContentType = “application/x-www-form-urlencoded”

$request.UserAgent = “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)”

return $request.GetResponse().StatusCode


function RecurseSite() {
write-output (“Site: $($SiteIdentity.Url) – $($SiteIdentity.Title)” | format-list)
$cred = [System.Net.CredentialCache]::DefaultNetworkCredentials

if ($SiteIdentity.Webs.Count -gt 0) {
foreach  ($subweb in $SiteIdentity.Webs) {
$output = WarmupSite -NetworkCred $cred -Web $subweb
$output | Out-file -FilePath “C:\isd\output\$($subweb.Title).txt”
RecurseSite -SiteIdenitity $subweb
else {
$output = WarmupSite -NetworkCred $cred -Web $SiteIdentity
$output | Out-file -FilePath “path to local network folder\$($SiteIdentity.Title).txt”

$webappservices = (Get-SPFarm).services | ? {$_.typename -eq “Microsoft SharePoint Foundation Web Application” }

foreach ($webapp in $webappservices.WebApplications) {
foreach ($sitecollection in $webapp.Sites) {
write-output “Site collection: $($sitecollection.Url)”
RecurseSite -SiteIdentity $($sitecollection.RootWeb)

I also added a “start-sleep 1”¬†as SharePoint 2010 would go crazy if i just let it run without it (too many SP objects).

Disclaimer – this code is provided “AS IS”..should be no danger in running it, however, clean it up as it’s a subset of my own code here (doing other things too) and is a cut n’ paste n’ edit.

Powershell – Add SSL Certificate to IIS

I recently had the need to apply an SSL certificate to a web site and this had to be done via Powershell.

I was looking around and trying to ascertain the easiest way to do it – without having to rely too heavily on the skills/knowledge/experience of the person deploying the script.

Found plenty of ways to do it, but all required more than 1 step and it really needed to be as simple as possible. Easiest way was really to use the CertObj COM Object.

So here’s what i came up with…Nothing inspirational, however it might help somebody else out that’s stuck in the same situation.