Pages

11 November 2011

Lock or Unlock all Site Collection in a Web Application

ISSUE DESCRIPTION:
For many reason, like a maintenance window on a SharePoint Farm, you might want to lock all the site collection from a Web Application

SOLUTION:
I have created an automated script that will do that for you.

SPSiteCollectionLockScript:

param (
    [string]$WebAppUrl = $(throw "Missing WebApp URL (please use -webappurl [URL])"),
    [string]$LockState= $(throw "Missing LockState (please use -lockstate [Unlock/ReadOnly])")
)

#Addin SharePoint2010 PowerShell Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

$WebApp = Get-SPWebApplication $WebAppUrl
$AllSites = $WebApp | Get-SPSite

#Set each SiteCollection with the lockstate defined
foreach ($Site in $AllSites)
    {
    Write-Host "Setting " -nonewline
    Write-Host $Site.url -ForegroundColor Yellow -nonewline
    Write-Host " to $lockState..." -nonewline
    Set-SPSiteAdministration -LockState $lockState -Identity $Site.url
    Write-Host "[OK]" -foregroundcolor green
    }

Paste the above code in a PowerShellScript file, like [SPSiteCollectionLock.ps1] and copy it on your local SharePoint Server Drive.

Launch the script from a Windows Powershell Cmd Prompt using the following parametters:
.\SPSiteCollectionLock.ps1 -webappurl <URL> -lockstate [Unlock/ReadOnly]



Et voila !

12 comments:

Anonymous said...

Read all the related Posts:


How to do Website Compatibility Testing (Made Simple)

7 steps to select Automated Software Testing Tools

64 Software Manual Testing Interview Questions

Why need Software Testing Tools?

Overview of Manual Software Testing

Embedded Software Testing - Overview

Automation vs Manual Software Testing

Standard definition of software testing

What parameters to consider for Performance Testing?

JAHAN said...

Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
Best Selenium Training in Chennai | Selenium Training Institute in Chennai | Besant Technologies

sweety ganga said...

I have picked cheery a lot of useful clothes outdated of this amazing blog. I’d love to return greater than and over again. Thanks! 
angularjs Training in online

angularjs Training in bangalore

angularjs Training in bangalore

angularjs Training in btm

sweety ganga said...

Well somehow I got to read lots of articles on your blog. It’s amazing how interesting it is for me to visit you very often.
angularjs Training in online

angularjs Training in bangalore

angularjs Training in bangalore

angularjs Training in btm

Mouni yoga said...

I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thx again!
Python training in marathahalli | Python training institute in pune

Mouni yoga said...

Thanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts
Python training in marathahalli | Python training institute in pune

sarah blossom1234567 said...

Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
Online DevOps Certification Course - Gangboard
Best Devops Training institute in Chennai

sarah blossom1234567 said...

This is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. 
Online DevOps Certification Course - Gangboard
Best Devops Training institute in Chennai

simbu said...

I am really very happy to find this particular site. I just wanted to say thank you for this huge read!! I absolutely enjoying every petite bit of it and I have you bookmarked to test out new substance you post.
Java training in Chennai | Java training in Bangalore

Java interview questions and answers | Core Java interview questions and answers

Ezhil K S said...

This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.
Data Science Training in Indira nagar
Data Science training in marathahalli
Data Science Interview questions and answers

vijay antony said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in chennai

vijay antony said...

Wow it is really wonderful and awesome thus it is very much useful for me to understand many concepts and helped me a lot. it is really explainable very well and i got more information from your blog.

rpa interview questions and answers
automation anywhere interview questions and answers
blueprism interview questions and answers
uipath interview questions and answers
rpa training in chennai

Post a Comment