ISI logo
SharePoint Tip of the Month


January 2011
Greetings!
 
There is a lot of press these days about using Powershell with SharePoint 2010.  This is a great new feature of 2010, but you can use Powershell with SharePoint 2007 as well, you just have to be a little more familiar with the SharePoint object model.

___________________________________________________________________

One thing I find we have to do quite often is check all the sites in a SharePoint web application for a particular reason. In large deployments, it rapidly becomes tedious doing it manually. This Powershell script shows how to use nested loops to go through all the sites in all the site collections in a web application and display the site title.
___________________________________________________________ 

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$webapp = [Microsoft.SharePoint.Administration.SPWebApplication]::Lookup("http://austin64")


foreach ($site in $webapp.Sites) {
    $rootweb = $site.OpenWeb();
    Write-Host Site Collection = $rootweb.Title;
    foreach($web in $rootweb.Webs) {
        Write-Host Site = $web.Title;
    }
}


$rootweb.Dispose();
$site.Dispose();

 

 

You can see that we're looking into a web application at the URL http://austin64, hosted on my development system.  The outer foreach loop goes through all the site collections in the web application, the inner foreach loop goes through all the sites in each site collection.  And we're simply writing the titles to the console.  The Write-Host statements can replaced with any kind of logic to accomplish almost anything.  Check out the WSS 3.0 SDK for more ideas.


Powershell is a powerful way to administer large SharePoint deployments. Enjoy!

 

 _________________________________________________________________

ISI is the founder of the DFW SharePoint Community, one of the oldest and largest SharePoint user groups. Register to come to one of our meetings, which are free to attend. If you're not already a member, it's free to join! 
 
If you have a SharePoint question you'd like us to answer, and possibly use for the next Tip of the Month, email it to us!
 
For assistance or more information, visit us at www.isi85.com or email Dan Hooper at dhooper@isi85.com.

 

 

Sincerely,


Dan Hooper | Principal | Integrated Services, Inc.
4144 N. Central Expwy, Suite 430  |  Dallas, TX  75204
Phone: 214.526.7680 x 101 | dhooper@isi85.com

 


Integrated Services, Inc.                                    
2008 winner logo small
Turning Data Into Profit
 
25 Years of Credibility & Trust

 

Join our email list         Check out our events