SharePoint Online: Add Calendar Item using PowerShell

Requirement: Add Calendar event in SharePoint Online using PowerShell
PowerShell to Add calendar event in sharepoint online

PowerShell to Add New Item in SharePoint Online Calendar
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

$SiteURL = ""
$CalendarName = "Team Calendar"

Try {
    #Setup Credentials to connect
    $Cred= Get-Credential
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Get the Calendar list
    $CalendarList = $Ctx.web.lists.GetByTitle($CalendarName)

    #Add Calendar Item
    $ListCreationInfo = New-object Microsoft.SharePoint.Client.ListItemCreationInformation
    $ListItem = $CalendarList.AddItem($ListCreationInfo)
    $ListItem.ParseAndSetFieldValue("Title", "Townhall Meeting")
    $ListItem.ParseAndSetFieldValue("Description", "Global Townhall Meetings - Yearly schedule")
    $ListItem.ParseAndSetFieldValue("Location", "Ballroom")
    $ListItem.ParseAndSetFieldValue("EventDate", "01/01/2019 09:00 AM")
    $ListItem.ParseAndSetFieldValue("EndDate", "01/01/2019 06:00 PM")
    Write-host "Canlendar Event Added Successfully!" -f Green
Catch {
    write-host -f Red "Error Adding Calendar Item!" $_.Exception.Message
To Set "All Day Event", set flag "fAllDayEvent" = $true;

PnP PowerShell to Add Calendar Event in SharePoint Online
$SiteURL = ""
$CalendarName = "Team Calendar"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Add Event to Calendar
Add-PnPListItem -List $CalendarName -Values @{"Title" = "Team Meeting"; "Description"= "Monthly Team Meeting"; "Location"= "Ballroom"; "EventDate" = [datetime]"01/01/2019 8AM"; "EndDate"=[datetime]"01/01/2019 6PM";}

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.