Update Site Default Page(Welcome Page) Content Type with PowerShell

This is a script that you can use to update a content type of your default page. With a little modification you can use bits of this script to update any page or list item content type.

param(
[string]$url
)

Start-Transcript -Path “output.log” -Append -Force -Confirm:$false

if (-not $url)
{
Write-Host “Specify site url in url parameter” -foregroundcolor red
return
}
Write-Host “##################################################” -foregroundcolor White
Install-SPFeature -Path “feature name”
Write-Host “Feature was sucessfully installed” -foregroundcolor green
Enable-SPFeature -Identity “feature name” -Url $url
Write-Host “Feature was sucessfully activated on” $url “site” -foregroundcolor green

Write-Host “##################################################” -foregroundcolor White

Write-Host “Opening Root Site” $url -foregroundcolor green

$web = Get-SPWeb $url
Write-Host “Retrieving default Page” -foregroundcolor yellow
$welcomePage = $web.GetListItem($web.RootFolder.WelcomePage)
Write-Host “Assigning the new content type to the default Page” -foregroundcolor yellow
$welcomePage[“ContentTypeId”] = $welcomePage.ParentList.ContentTypes[“new content type name”].Id
Write-Host “Updating the default Page” -foregroundcolor yellow
$welcomePage.SystemUpdate()
Write-Host “Update finished to the default Page” -foregroundcolor green
Write-Host “##################################################” -foregroundcolor White
Stop-Transcript

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s