Freitag, 20. Januar 2012

Powershell script how to change a property of list(s) or page(s)

Sometimes you might have to change a property of a list or page in a site-collection. Maybe the amount of items is so large, that handling this manually would take ages to do.
Here is a script, where I change all the list-titles to add the " 1" to it.

$sites = Get-SPSite
foreach($site in $sites)
{
$web = $site.RootWeb
foreach($list in $web.lists)
{
$title = $list.Title
$list.Title = "$title 1"
$list.Update()
}
}


This code changed now the title of each list in your web-pplications to it's origin name plus the string " 1". You can also check for a specific site-collection to make the changes at:
$sites = Get-SPSite
foreach($site in $sites)
{
if($site.Url -eq "%url of the site-collection you want to make the changes in%")
{
$web = $site.RootWeb
foreach($list in $web.lists)
{
$title = $list.Title
$list.Title = "$title 1"
$list.Update()
}
}
}

Keine Kommentare:

Kommentar veröffentlichen