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.

1 Answer 1


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.

  • 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. Commented Apr 8, 2011 at 19:01
  • Updated the code sample - should help you out better. Commented Apr 8, 2011 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 } } } Commented Apr 8, 2011 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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