开发者

Is there a way to globally change Title list field back to 'Title' in MOSS2007

Sooner or later in each SharePoint developer's life one is fooling around with content types and renames the Title field in the Item base type. This has two effects:

  • All new lists have the new name instead of "Title".
  • All lists in the site collection have their title fields renamed.

Now, I've set the Item content type back OK, but I'm stuck with hundreds, if not thousands, of lists that now have a field called 'Publication Title', which I'd like to change back to 'Title'.

After some Googling, I'm quickly becoming acquainted with powershell and am preparing a script to travers开发者_如何转开发e the site collection and rename all the title fields.

But I'm sure I'm not the first one to do this and I'm sure I'm not the first to think of this solution. Anyone got some code lying about that would sort this out?

Oh yeah, this is on the production farm. Ha ha.


So I guess that's a no...

I wrote a powershell script that does the renaming:

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null

function global:Get-SPSite($url){
    return new-Object Microsoft.SharePoint.SPSite($url)
}

#Change these variables to your site URL and list name
$siteColletion = Get-SPSite("http://go.snap-undp.org/focusareas/")
$webs = $siteColletion.allwebs

#Walk through each site in the site collection
#use FOR loops because collections break when you update them
for($webIndex=0;$webIndex -ne $webs.count;$webIndex++){
    #use this for output
    $webTitle = $webs[$webIndex].title.toString()
    "PROCESSING $webTitle"

    #loop though each list in the current website
    for($i=0;$i -ne $webs[$webIndex].lists.count;$i++){

        #this is used for output and to make the code a little more readable
        $listTitle = $webs[$webIndex].lists[$i].toString()

        #loop through each field in the lsit, looking for the offending name
        foreach($field in $webs[$webIndex].lists[$i].fields){
            if($field.title -eq "Publication Title"){
                if($listTitle -eq "Participants" -or $listTitle -eq "User Account Request List"){
                    $field.title = "Last Name"
                    "workshop update to $listTitle"
                }else{
                    $field.title = "Title"
                    "normal update to $listTitle"
                }
                #$field.Update()
                break
            }
        }
    }
}
#Dispose of the site object
$siteColletion.Dispose()

This is pretty specific. It looks for columns named "Publication Title" (the wrong name) and renames them to Title, unless the list is named "Participants", in which case it renamed is "Last Name". Modify to taste.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜