Return to Snippet

Revision: 45129
at April 25, 2011 07:16 by nickaranz


Initial Code
function AddCalendarWP($web)
{
	$wpPage = $web.GetFile("Pages/home.aspx")
	if($wpPage -ne $null)
	{
		if($wpPage.CheckedOutByUser -ne $null){$wpPage.UndoCheckOut()}
		$wpPage.CheckOut()
		$list = $web.Lists["mhcCalendar"]
		$wpManager = $wpPage.GetLimitedWebPartManager([System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

		$wpView = New-Object "Microsoft.SharePoint.WebPartPages.ListViewWebPart"
		$wpView.ListName = $list.ID.ToString("B").ToUpper()
		$wpView.ViewType = "Calendar"
		$wpView.ViewGuid = $list.DefaultView.ID.ToString("B").ToUpper()
		$wpView.Title = "Calendar"
		$wpManager.AddWebPart($wpView,"Center",6)
		$wpManager.SaveChanges($wpView)
		$wpManager.Dispose()
		$wpPage.CheckIn("")
		$wpPage.Publish("from Powershell")
	}
	else
	{
		Write-Host -ForegroundColor Red "Home Page not found. Calendar web part not added"
	}
}

Initial URL

                                

Initial Description

                                

Initial Title
Add Calendar View Web Part  PowerShell Script

Initial Tags
sharepoint

Initial Language
Windows PowerShell