We always have patching done in our Windows 2008-2012 servers and sometimes they break our sites in our SharePoint 2010-2013. We needed to automate testing or opening all of our sites and checking them to see if they are loading properly.
Requirements:
- PowerShell
- Admin Access
- Windows Server 2010 – 2013
- SharePoint Server 2010 – 2013
Solution:
“NOTE: Please forgive this horrible code! It can be completed better by creating 1 loop and with a modulus operator. There’s also other things here too but I want to look back at this Post and see how horrible my coding was back then. I had functionality in mind instead of design.”
What the script does is open all of your SharePoint sites in 4 sections linearly and in order to continue to the next session, just press any key.
$navOpenInBackgroundTab = 0x1000;
#1. Grab all sites
$websites = @(“”)
foreach($website in $websites)
{
$websites = get-spsite -limit all
}#2. Remove string SPSite Url=
$urlsToLaunch = @()
foreach($website in $websites)
{
$urlsToLaunch += $website -replace “SPSite Url=”,””
}#3. Launch url
if ( $urlsToLaunch.Length -le 15 ) {
$ie = new-object -com InternetExplorer.Application;
for($i=0; $i -le $urlsToLaunch.Length-1; $i++)
{
$ie.Navigate2($urlsToLaunch[$i], $navOpenInBackgroundTab);
$ie.Visible = $true;
}
}
else{
$length = $urlsToLaunch.Length-1
$splitInto4 = [Math]::truncate($length / 4)
$ie = new-object -com InternetExplorer.Application;
for($i=0; $i -le $splitInto4; $i++)
{
$numberOfSitesToBeLaunched = $urlsToLaunch.Length-1 – $i
write-host “Sites to be launched: ” $numberOfSitesToBeLaunched
$ie.Navigate2($urlsToLaunch[$i], $navOpenInBackgroundTab);
$ie.Visible = $true;
}Write-Host “Press any key to open second batch of sites (2/4)…”
$continueKey = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)$ie = new-object -com InternetExplorer.Application;
for($i=$splitInto4; $i -le $splitInto4*2; $i++)
{
$numberOfSitesToBeLaunched = $urlsToLaunch.Length-1 – $i
write-host “Sites to be launched: ” $numberOfSitesToBeLaunched
$ie.Navigate2($urlsToLaunch[$i], $navOpenInBackgroundTab);
$ie.Visible = $true;
}Write-Host “Press any key to open third batch of sites (3/4)…”
$continueKey = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)$ie = new-object -com InternetExplorer.Application;
for($i=$splitInto4*2; $i -le $splitInto4*3; $i++)
{
$numberOfSitesToBeLaunched = $urlsToLaunch.Length-1 – $i
write-host “Sites to be launched: ” $numberOfSitesToBeLaunched
$ie.Navigate2($urlsToLaunch[$i], $navOpenInBackgroundTab);
$ie.Visible = $true;
}Write-Host “Press any key to open last batch of sites (4/4)…”
$continueKey = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)$ie = new-object -com InternetExplorer.Application;
for($i=$splitInto4*3; $i -le $length; $i++)
{
$numberOfSitesToBeLaunched = $urlsToLaunch.Length-1 – $i
write-host “Sites to be launched: ” $numberOfSitesToBeLaunched
$ie.Navigate2($urlsToLaunch[$i], $navOpenInBackgroundTab);
$ie.Visible = $true;
}
}