/ Published in: Windows PowerShell
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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" } }