I am working on a script to create a Calendar in SharePoint site and then add it to a publishing page as part of site provisioning.

By using the similar to what is shown in this forum, i am able to add Calendar web part but its view by default is setting it as 'Calendar'. whereas i would like to have it added with 'All Events' view.


playing around with ViewType property did not take me anywhere.

$wpView.ViewType = "Calendar"

Any suggestions on how can we set the properties of this web part to be 'All Events' view when it is added to the page?

  • This might be helpful if you can use silver light, sharepoint.stackexchange.com/questions/33700/… Jun 19, 2013 at 20:11
  • No silver light. My script is all set except this one property. Once it is added as calendar view to the page, it is allowing to change it to 'all events' through UI. So there has to be a way to do it with powershell too, right?
    – svs
    Jun 19, 2013 at 20:24

2 Answers 2


Change this line:

$wpView.ViewGuid = $list.DefaultView.ID.ToString("B").ToUpper()


$wpView.ViewGuid = $list.Views[0].ID.ToString("B").ToUpper() //Set To "All Events" View
$wpView.ViewType = "Html"
  • When changed the code to that, it is returning this error: "Property 'ViewGuid' cannot be found on this object; make sure it exists and is settable"
    – svs
    Jun 20, 2013 at 12:21
  • Make sure that "$wpView" is not null.
    – Raymond
    Jun 21, 2013 at 2:09
  • ok, thanks. But again another question, what is the ViewType for having 'Summary View' to be added by default instead of 'All events'? TIA.
    – svs
    Jul 2, 2013 at 14:52

The examples gave me an invalid view exception, here is a version that did work

        # create new webpart 
        Write-VerboseLog "Creating new webpart"
        $webpart = New-Object Microsoft.SharePoint.WebPartPages.ListViewWebPart
        $webpart.ListName = $list.ID.ToString("B").ToUpper()
        $webpart.ViewGuid = ($list.Views | Where-Object { $_.TYPE -eq "CALENDAR" }).ID.ToString("B").ToUpper()
        $webpart.Title = $ListTitle

        # add webpart
        $webpartManager.AddWebPart($webpart, $Zone, $ZoneIndex)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.