Using PowerShell to make an entire web application read-only


STSADM.exe was great in SharePoint 2007. It provided some really good functionality, some of which was not available in the GUI. STSADM is still available in SharePoint 2010, but why anybody would use it is beyond me. PowerShell is not only much more powerful (hence the name), but it’s here to stay.
There are loads of examples of scripts online for various SharePoint tasks, and there are lots of one-offs that I’ve made scripts for that I doubt anybody else would use; however, there is one thing I think everyone may want at some point, the ability to make an entire web application read-only. Could you make the content database read-only? Sure, but maybe you want just the sites to be read-only.
In 2007, you could set a site collection as read-only via STSADM; but I was never able to find a “good” way to make an entire web application read-only. In SharePoint 2010, it’s very easy with a few commands and a ForEach loop.
Here’s the advanced function:
function Set-LockState {
<#
.SYNOPSIS
Use this PowerShell script to set the Lock State of a SharePoint Web Application to Unlock, ReadOnly, NoAdditions or NoAccess.
.DESCRIPTION
This PowerShell script uses Set-SPSiteAdministration to set the Lock State of a SharePoint Web Application.
.EXAMPLE
C:\PS>.\SetAllSitesInAWebAppToReadOnly.ps1 -WebAppUrl http://intranet -LockState ReadOnly
This example sets all site collections in a web application at http://intranet to read-only.
.NOTES
This PowerShell script sets the Lock State of a SharePoint Web Application.
.LINK
http://www.iccblogs.com/blogs/rdennis
 http://twitter.com/SharePointRyan
.INPUTS
None
.OUTPUTS
None
#>

## Input Parameters ##
[CmdletBinding()]
Param(
[string]$WebAppUrl=(Read-Host "Please enter a Web Application URL (Example: http://intranet)"),
[string]$LockState=(Read-Host "Please enter a Lock State (Examples: Unlock, ReadOnly)")
)
## Add SharePoint Snap-in ##
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
### No need to modify these ###
$WebApp = Get-SPWebApplication $WebAppUrl
$AllSites = $WebApp | Get-SPSite

############################# The Script - no need to modify this section #############################
## Start SP Assignment for proper disposal of variables and objects ##
Write-Host "Starting SP Assignment..." -ForegroundColor Green
Start-SPAssignment -Global
## Use a ForEach-Object loop and Set-SPSiteAdministration to set an entire web application ##
Write-Host "Setting $WebAppUrl to $lockState..." -ForegroundColor Yellow
$AllSites | ForEach-Object { Set-SPSiteAdministration -LockState $lockState -Identity $_.url }
## End SP Assignment for proper disposal of variables and objects ##
Write-Host "Disposing of SP Objects.." -ForegroundColor Green
Stop-SPAssignment -Global
## Tell us it's done ##
Write-Host "Finished!" -ForegroundColor Green
}

First 2010 Implementation Complete! (Well, sort of)


As of 11/3/2010, my first “real” 2010 implementation is complete for my current client. This implementation was a small farm consisting of a SQL database server and a single SharePoint server (both VMs).

The SharePoint 2010 VM is Windows Server 2008 R2 with 8GB of RAM and it is an Enterprise license.

The migration was from MOSS 2007 Enterprise and I utilized the database attach method for the migration piece. In total, there were 3 content databases, 2 web applications and 76 site collections with a few hundred subwebs.

So far so good and the migration itself was very smooth.

Now the real fun begins, utilizing the new 2010 functionality!

Prevent theme inheritance on Publishing sub-sites


If you’ve created publishing sites and then tried changing the theme on a sub-site, you’ve probably run into this issue:

You apply the theme and nothing changes!!!!!

For some reason or another, when Publishing features are enabled; sub-sites inherit the theme from their parent site. You can prevent this from happening by doing the following:

Open up the default master page for the site in SharePoint Designer and look for the following tag:

Either delete or comment-out this tag and then save your master page, you should no longer have this issue.

SharePoint/Office Integration “Gotchas”


While testing with a domain test account, I discovered an interesting issue/bug/feature with Office and SharePoint integration.

Using the domain account with “Restricted Reader” permissions, I navigated to a SharePoint Document Library and clicked the document icon to open in Word.

Word launched as expected with the yellow “You must checkout this document” warning/dialog. Seems normal and in fact it is, however clicking the “Check out” button as a restricted reader should NOT allow you to check the document out. It did. Initially this seems like a bug, but after some trial, error and thought; it’s not.

Issue: I logged onto the SharePoint site as the test user, however I’m logged into the MACHINE as DOMAIN\Username. Word thinks of us as who we are logged into the machine as, NOT who we’re logged into SharePoint as.

Resolution: To accurately test things like this, it is highly recommended to log onto the machine with the test account that you intend to use. This will prevent issues like this, and your test will be more accurate.

Copy SharePoint Navigation across Site Collections


Have you every been tasked with consistent top-level navigation across Site Collections? Sure you have, we all have! Have you heard about the Gary Lapointe STSADM Extensions? I just recently found out about them, and I’m glad I did…

Without Gary’s extensions, you must manually enter the navigation on each site collection; no fun. With Gary’s extensions, you can copy the navigation from a source site collection to as many destination site collections as your heart desires.

This recently saved me a TON of time and since it’s an STSADM command, it can easily be scripted, scheduled, etc. The possibilities are truly endless.

I only used one of Gary’s 144 commands (gl-copynavigation), so I’m sure there is a ton of stuff that these can do that I don’t know of. Have you used these before? Tell me your success stories!

Gary LaPointe:
http://stsadm.blogspot.com/2007/08/stsadm-commands_09.html