Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Warm-up script unable to wake up a site

$
0
0

Hi There,

I am trying a warm script on 2013 but some sites fail to open.

Reason:

Site: https:// xyz.net
Exception calling "GetResponse" with "0" argument(s): "The remote server returned an error: (401) Unauthorized."
At C:\Users\zspsetupdev\Desktop\Newspwakeup\sa.ps1:86 char:5
+     $response = $request.GetResponse()
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : WebException

Failed waking :

----------------------------

Here is my code below, Please suggest :(

if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
    Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}


$InputfileName="SP2013-warmup-extra.txt";
$LogfileName="scriptrun.log";

$ScriptPath = Split-Path -parent $MyInvocation.MyCommand.Definition;

$extrasitelistfile= $ScriptPath + "\" +$InputfileName;
$Logfile=$ScriptPath + "\" + $LogfileName;

#Check if log file exists and delete. Each time new file is created
if (Test-Path  ($Logfile))
{
   Remove-Item $Logfile
}


Function LogWrite
{
   Param ([string]$logstring)
   write-host $logstring;
   $now=Get-Date -format "dd-MMM-yyyy HH:mm:ss" ;
   $msg= $now + " :: " + $logstring;

   Add-content $Logfile -value  $msg
}


Logwrite $extrasitelistfile
if (Test-Path  ($extrasitelistfile))
{
   Logwrite $extrasitelistfile "...File exists";
}
else
{
   Logwrite $extrasitelistfile "...File Not found" ;
}


function get-webpage([string]$url,[System.Net.NetworkCredential]$cred=$null)
{

  $wc = new-object net.webclient
  if($cred -eq $null)
  {
    $cred = [System.Net.CredentialCache]::DefaultCredentials;
  }
  $wc.credentials = $cred;
  return $wc.DownloadString($url);
}



function LoadSite([string]$url,[System.Net.NetworkCredential]$cred=$null)
{

	if($cred -eq $null)
	{
		$cred = [System.Net.CredentialCache]::DefaultCredentials;
	}

    $request = [System.Net.WebRequest]::Create($url)
    $request.AllowAutoRedirect = $true
    $request.proxy = [System.Net.WebRequest]::DefaultWebProxy

    $request.Credentials = $cred
    $request.ContentType = "application/x-www-form-urlencoded"
    $request.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED","f")

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

    $response = $request.GetResponse()
    return $response.StatusCode
}

function WarmupSite([string]$url,[System.Net.NetworkCredential]$cred=$null)
{

	Logwrite "Site: $url"
	$result = LoadSite -url $url -cred $cred;

	If ($result -eq "OK")
	{
		Logwrite "Woke up $($_.Url)";"Woke up $($_.Url)"|write-host -back darkgreen
       }
	else
	{
		Logwrite "Failed waking $($_.url): $result";"Failed waking $($_.url): $result" | write-host -back darkred
       }

}


#This passes in the default credentials needed. If you need specific
#stuff you can use something else to elevate basically the permissions.
#Or run this task as a user that has a Policy above all the Web
#Applications with the correct permissions

Logwrite "Starting warmup script"
Logwrite "Setting default credentials"

$cred = [System.Net.CredentialCache]::DefaultCredentials;


Logwrite "Getting web applications"
# Get all the webapplications on the farm and loop through individual sites
$apps = get-spwebapplication -includecentraladministration

foreach ($app in $apps)
{
	$sites = get-spsite -webapplication $app.url -limit all
		foreach ($site in $sites)
		{
	              WarmupSite -url $site.Url -cred $cred;
		}
}



Logwrite "Reading site url's from the file"
# Warm up other sites specified in SP2010-warmup-extra.txt file (such as Search, other external URL)

if (test-path $extrasitelistfile)
{
Logwrite $extrasitelistfile "found";
  $extrasites = get-content $extrasitelistfile
  foreach ($site in $extrasites)
  {
    # Call warmup site with SiteURL and credentials
	WarmupSite -url $site -cred $cred;
  }
}

Logwrite "Script execution completed"

Thanks in advace :)



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>