Replies: 1 comment 1 reply
-
Here's how you can do this with PnP PowerShell. I needs to be done using SPO Rest API (see my blog for further details) $list = New-PnPList -Title "ModernCalendar" -Template Events
Set-PnPList -Identity $List -ListExperience NewExperience # Set list experience to force the list to display in Modern
$viewTitle = "Calendar"
Remove-PnPView -Identity $viewTitle -List $list -Force #Remove Classic Style Calandar Default View
$viewCreationJson = @"
{
"parameters": {
"__metadata": {
"type": "SP.ViewCreationInformation"
},
"Title": "Calendar",
"ViewFields": {
"__metadata": {
"type": "Collection(Edm.String)"
},
"results": [
"EventDate",
"EndDate",
"Title"
]
},
"ViewTypeKind": 1,
"ViewType2": "MODERNCALENDAR",
"ViewData": "<FieldRef Name=\"Title\" Type=\"CalendarMonthTitle\" /><FieldRef Name=\"Title\" Type=\"CalendarWeekTitle\" /><FieldRef Name=\"Title\" Type=\"CalendarWeekLocation\" /><FieldRef Name=\"Title\" Type=\"CalendarDayTitle\" /><FieldRef Name=\"Title\" Type=\"CalendarDayLocation\" />",
"CalendarViewStyles": "<CalendarViewStyle Title=\"Day\" Type=\"day\" Template=\"CalendarViewdayChrome\" Sequence=\"1\" Default=\"FALSE\" /><CalendarViewStyle Title=\"Week\" Type=\"week\" Template=\"CalendarViewweekChrome\" Sequence=\"2\" Default=\"FALSE\" /><CalendarViewStyle Title=\"Month\" Type=\"month\" Template=\"CalendarViewmonthChrome\" Sequence=\"3\" Default=\"TRUE\" />",
"Query": "",
"Paged": true,
"PersonalView": false,
"RowLimit": 0
}
}
"@
Invoke-PnPSPRestMethod -Method Post -Url "$url/_api/web/lists/GetByTitle('$($list.title)')/Views/Add" -ContentType "application/json;odata=verbose" -Content $viewCreationJson
Set-PnPView -List $list -Identity $viewTitle -Values @{DefaultView=$true;MobileView=$true;MobileDefaultView=$true} #Set View To Be Default
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a way to add a modern calendar view using PnP.PowerShell?
I have tried Add-PnPView -ViewType Calendar and it adds a classic calendar view.
Beta Was this translation helpful? Give feedback.
All reactions