2

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
$spView.ViewFields.Delete("Country")
$spView.Update()
1

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      
    $spView.ViewFields.Delete("Country")      
    $spView.Update() 
}

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

Hope that helps

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

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:

http://geekswithblogs.net/bjackett/archive/2011/09/19/powershell-script-to-traverse-all-sites-in-sharepoint-2010-or.aspx

|improve this answer|||||

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.