SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have close to 1000 subsites in a site collection. I would like to remove the country column from the defualt view in each site with one power shell script. This is how I would do it for one site, but how do I get this script to run for all subsites?

$spWeb = Get-SPWeb "http://server_name/sitecollection/"
$spList = $spWeb.GetListFromUrl("property documents/forms/AllItems.aspx")
$spView = $spList.DefaultView
share|improve this question

You can try the SPSite.AllWebs property...

Check out this link, as it is very similar.

$site = Get-SPSite -Identity "http://server_name/sitecollection/"
$web = $site.RootWeb
foreach($spList in $web.Lists) { 
    $spView = $spList.DefaultView      

This is assuming all lists have the Country field. You can check that if all of them don't...

Hope that helps

share|improve this answer
+1 That's what I would do. – bgmCoder Dec 20 '12 at 22:18

There is a script that you can use to traverse through all sites and subsites, to get you started.

The script can be found here:

share|improve this answer

Your Answer


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.