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

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

  • +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:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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