Last active
December 25, 2015 15:59
-
-
Save grantcarthew/7002208 to your computer and use it in GitHub Desktop.
Invokes a standard web request against all the sites in SharePoint.
http://uglygizmo.blogspot.com.au/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.Synopsis | |
Invokes a standard web request against all the sites in SharePoint. | |
.Description | |
There are some dependencies to run this script as follows; | |
The account used to run this script will need read access to all | |
sites for the initialization to fully succeed. | |
This script is required to be run on a SharePoint server or a | |
machine with the Microsoft.SharePoint.PowerShell dll registered. | |
Requires PowerShell v3.0. | |
#> | |
[CmdletBinding()] | |
Param | |
() | |
"Importing the PowerShell cmdlets." | |
$ver = $host | select version | |
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"} | |
Add-PsSnapin Microsoft.SharePoint.PowerShell | |
"Creating an Internet Explorer object for navigation." | |
$ie = New-Object -ComObject InternetExplorer.Application | |
"Enumerate the SharePoint sites." | |
$Webs = Get-SPWebApplication -IncludeCentralAdministration | Get-SPSite | Get-SPWeb | |
"Navigating to all $($Webs.Count) sites." | |
foreach ($Web in $Webs) | |
{ | |
"Initializing $($Web.URL)" | |
try | |
{ | |
$ie.Navigate($Web.URL) | |
while ($ie.Busy) | |
{ | |
Start-Sleep -Seconds 1 | |
} | |
"Title: $($ie.Document.title)" | |
} | |
catch | |
{ | |
Write-Host -Object ("Status: " + $Error[0].Exception.Message) -ForegroundColor Yellow | |
} | |
} | |
$ie.Quit() | |
"SPWeb Initialization Complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script has been updated to use an InternetExplorer.application COM object rather than the Invoke-WebRequest cmdlet. I found the Invoke-WebRequest was not doing a complete job at warming up the pages in SharePoint because it would not request embedded elements on the returned pages.
To see the old version, click the revisions link at the top of this page.