Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'm a beginner to Powershell 1.0 and I'm looking to pull some information out of the Sharepoint 2007 farm as we start the upgrade to 2010 planning. This is what I'm wanting to do, but having some difficulty visualizing how to string it all together.

I want to iterate through all the webs in all site collections in a web application and list the site URL and the LastContentModifiedDate in the output and ideally output it to a csv or text file for analysis in Excel.

I can get the web app I want by using $spweb = get-spwebapplication | where{ $_.Displayname -like "*collab*"} but I'm not sure how to get all the site collections from the web app to iterate through all the spwebs.

I'm importing the functions into my profile provided by Zach Rosenfield.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Updated answer

I'm pretty sure that Get-SPWebApplication does not work with WSS 3.0 or MOSS 2007 (unless you have a custom cmdlet), but the code you need is below.

foreach ($wa in get-spwebapplication | where{ $_.Displayname -like "*collab*"})
{
    Write-Host $wa
    foreach ($site in $wa.Sites)
    {
        Write-Host $site
        foreach ($web in $site.Webs)
        {
            Write-Host $web         
        }
    } 
}

You just need to get the data required on each $web and do something with it.

share|improve this answer
    
That makes sense, but I'm not sure how to get a list of site collections to pass into that. To get site information (to get webs), I need to do a Get-SPSite call which requires a url parameter. So I don't know how to go from a web app to a list of site collections in that web application. –  PirateEric Apr 8 '11 at 19:01
    
Updated the code sample - should help you out better. –  Charles Lee Apr 8 '11 at 19:08
    
It wasn't pretty but I used what you had and came up with this: foreach ($wa in get-spwebapplication | where{ $_.Displayname -like "*collab*"}) { #Write-Host $wa foreach ($site in $wa.Sites) { #Write-Host $site.url, $Site.LastContentModifiedDate foreach ($web in $site.AllWebs) { write-output "URL" $web.url | out-File C:\out.txt -append write-output "Last MOdified" $Site.LastContentModifiedDate | out-File C:\out.txt -append } } } –  PirateEric Apr 8 '11 at 20:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.