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 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()
share|improve this question
add comment

2 Answers 2

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

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

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

share|improve this answer
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.