$SharePointSiteUrl = "https://teamyedu.sharepoint.com/sites/Intranet"
$SharePointListName = "Mon Agenda Moderne"
$DefaultCalendarViewName = "Calendrier"
clear
Connect-PnPOnline -Url $SharePointSiteUrl -Interactive
$list = New-PnPList -Title "$SharePointListName" -Template Events
Set-PnPList -Identity $List -ListExperience NewExperience
Remove-PnPView -Identity $DefaultCalendarViewName -List $list -Force #Remove Classic Style Calendar Default View
#New Calendar View
$viewCreationJson = @"
{
"parameters": {
"__metadata": {
"type": "SP.ViewCreationInformation"
},
"Title": "$DefaultCalendarViewName",
"ViewFields": {
"__metadata": {
"type": "Collection(Edm.String)"
},
"results": [
"EventDate",
"EndDate",
"Title"
]
},
"ViewTypeKind": 1,
"ViewType2": "MODERNCALENDAR",
"ViewData": "",
"CalendarViewStyles": "",
"Query": "",
"Paged": true,
"PersonalView": false,
"RowLimit": 0
}
}
"@
Invoke-PnPSPRestMethod -Method Post -Url "$SharePointSiteUrl/_api/web/lists/GetByTitle('$SharePointListName')/Views/Add" -ContentType "application/json;odata=verbose" -Content $viewCreationJson
Set-PnPView -List $list -Identity "$DefaultCalendarViewName" -Values @{DefaultView=$true;MobileView=$true;MobileDefaultView=$true} #Set View To Be Default