SharePoint 2010 Wake Up Script as a Scheduled Task

So an Executive VP or Manager is the first person in the office in the morning, and ask you "Why is the intranet so slow every the morning?"

Well, IIS recycles daily at about 2:00am each night. This means that the first user request to access any SharePoint 2010 site will have to wait until the site "warms up" or "wakes up" before loading the page.

Lets change that! Below is a handy Powershell script that will query each top level site collection and send a request to the site. Lets take this Powershell script and combine it with a Windows scheduled task on the SharePoint web front end server(s). Lets start with the script:

//--Powershell Script Begin--

Add-PSSnapin Microsoft.SharePoint.PowerShell;

function Get-WebPage([string]$url)
{
$wc = new-object net.webclient;
$wc.credentials = [System.Net.CredentialCache]::DefaultCredentials;
$pageContents = $wc.DownloadString($url);
$wc.Dispose();
return $pageContents;
}

Get-SPAlternateUrl -Zone Default | foreach-object {
write-host $_.IncomingUrl;
$html = Get-WebPage -url $_.IncomingUrl;
}
//--Powershell Script End--

Step by Step Configuration

  1. Copy the Powershell script text above and save it as SharePointSiteWakeUp.ps1 on each of your SharePoint 2010 Web front end servers. Save the file in the "C:\Windows\" directory. 
  2. Next we will schedule a Windows Scheduled Task to run the Powershell script daily at 5:00am. (You can specify anytime after 2:15am).
  3. On your SharePoint 2010 Web Front End server(s), click 'Start' > 'Administrative Tools' > 'Task Scheduler' as shown below:   
  4. Next, Right click on 'Task Scheduler' and click 'Create Basic Task' as show below:                                                    
  5. Enter a Name for the Task and click 'Next'
  6. Set the Task Frequency to Daily and click 'Next'
  7. Set the scheduled daily Start time to 5:00 AM every 1 day and click 'Next'
  8. Choose the Action 'Start a Program' and click 'Next'
  9. Next, in the 'program/script' text box enter the following: powershell -file "C:\Windows\SharePointSiteWakeUp.ps1" then click 'Next': 
  10. You will receive a message that arguments have been included in the Program text box. Click 'Yes' to continue:                                        
  11. Review the Task Summary and click 'Finish' to complete the wizard: 

That is it! Now when the first user of the day goes to open a SharePoint site, it will respond in just 1-3 seconds instead of 30-45 seconds.

SQL Log File Cannot be Truncated or Shrunk Explained

Let's start by saying, this was a HUGE pain in the rear. So a client of mine is running SQL Server 2008 behind their SharePoint 2007 environment (this would also apply to SharePoint 2010), and one of the databases is 420MB's, but the Log File is 103GB's!!!

Wow, great catch, guess I will just set the recovery mode to Simple, and shrink the Log file right?
Wrong, its not that easy...

After about 2 days of research and sql queries, I ran into an MSDN article that explains where to look for the specific issue and resolve. Here are the steps I followed:


--Begin SQL commands--

--This command showed me the database was stuck in ‘REPLICATION’
SELECT name, log_reuse_wait_desc FROM sys.databases

--This command below removed the database from being stuck in ‘REPLICATION’ which should no unlock the database for maintenance/shrinking:
EXEC sp_removedbreplication SharedServices1_DB

--The following command shrinks the log file and sets the recovery mode back to Full.
USE SharedServices1_DB;

-- Shrink the truncated log file to 1 MB.
DBCC SHRINKFILE (2, 1);  -- here 2 is the file ID for trasaction log file,you can also mention the log file name (dbname_log)
GO

-- Reset the database recovery model.
ALTER DATABASE SharedServices1_DB
SET RECOVERY FULL;
GO

The end result, we have a healthy database, that is only 420mb’s and the log file is 1MB!

GUID URL Decoder/Encoder is Great!

I came across a very useful tool which will take an ugly, un-encoded GUID and automatically add the fancy stuff aka put it into a useful format. See the example below:

Original GUID: %7BDHJTY8B%2DJGU5%2D8FE6%2DAY38E%2D5DTU58F9L5DB%7D
Decoded GUID: {DHJTY8B-JGU5-8FE6-AY38E-5DTU58F9L5DB}

Check out the tool here: http://meyerweb.com/eric/tools/dencoder/

Fix Broken Alerts After a SharePoint 2007 to 2010 Migration

So after performing a DB attach upgrade for a client, I found that all the Alerts they had setup were broken.
Well, hello PowerShell, can you help me? (That's a silly question).

The following is a script I used via SharePoint Management Shell as an Administrator to retrieve a list of alerts for the entire Site collection: http://portalnew


Get Alerts for site collection:
Get-SPweb -site http://portalnew -limit all | ForEach-Object {$_.alerts|foreach-object{write-host $_.user $_.properties["siteUrl"] $_.properties["dispformurl"]}}

After performing the above script, I saw a handful of alerts looking for the old server name. The below script updates the server name for all alerts needing the update:

Update URL for broken alerts:
Get-SPweb -site http://portalnew -limit all | ForEach-Object {$_.alerts|foreach-object{$_.properties["siteUrl"] = "http://portalnew";$_.update()}}

Have fun with that!

How To: SharePoint 2007 Multiple File Check In / Check Out


So you uploaded a handful (or a few hundred) files to SharePoint 2007 and can't find a way to do a mass check-in for the documents. This tutorial will show you how to avoid checking in these files one at a time using the Manage Content and Structure Feature.
It is a very easy to use browser interface that allows you to move items and yes, check in and out multiple documents. To get to this feature we will use the Site Actions Menu. 
Please note you must have the proper permissions (contribution at least) and you will not see all the options from the screen shots below if you do not have full control to the Site Collection.
  1. Open the SharePoint Site. The Site Actions button is in the top right hand corner. Click 'Site Actions and Manage Content and Structure'.SharePoint File Check In or Out Step 1
  2. Navigate to the Document Library and folder containing the documents you wish to check in and click on it to expose the documents to the right.SharePoint Multiple File Check In or Out Step 2
  3. Now if you haven’t seen this check box before it simply selects all the boxes in the view. Click this select all in view or simply check the ones you need to check in or out.SharePoint Multiple File Check In or Out Step 3
  4. Highlights your selectionsSharePoint Multiple File Check In or Out Step 3-b
  5. Now using the Actions Menu select Check In or Out depending on your taskSharePoint Multiple File Check In or Out Step 4
Now you have successfully checked in or out multiple documents!

SharePoint 2010 Versions


Microsoft SharePoint Server 2010

Release Version KB
RTM 14.0.4762.1000 n/a
June 2010 CU 14.0.5114.5003 n/a
Aug 2010 CU 14.0.5123.5000 2352342
Oct 2010 CU 14.0.5128.2003 2394320
Dec 2010 CU 14.0.5130.5002 2459257
Feb 2011 CU 14.0.5136.5002 2475878
April 2011 CU 14.0.5138.5001 2512800
Service Pack 1 14.0.6029.1000 2460045

June 2011 CU (Refresh) 14.0.6106.5002 2536599
August 2011 CU 14.0.6109.5002 2553048
October 2011 CU 14.0.6112.5000 2596505
December 2011 CU
February 2012 CU
14.0.6114.5000
14.0.6117.5002
2597014
2597150