Búsqueda de sitios web

SharePoint Online: Agregar elemento de calendario usando PowerShell


Requisito: Agregar evento de calendario en SharePoint Online usando PowerShell.

PowerShell para agregar un nuevo elemento en el calendario de SharePoint Online

PowerShell es un potente lenguaje de secuencias de comandos que puede automatizar muchas tareas en SharePoint Online. Agreguemos eventos al calendario de SharePoint Online usando PowerShell:


#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"

#Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing/"
$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)
    $Ctx.load($CalendarList)
    $Ctx.ExecuteQuery()

    #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")
    $ListItem.Update()
    $Ctx.ExecuteQuery()
    Write-host "Calendar Event Added Successfully!" -f Green
}
Catch {
    write-host -f Red "Error Adding Calendar Item!" $_.Exception.Message
}

Para configurar el “Evento de todo el día”, establezca la bandera “fAllDayEvent”=$true;

PnP PowerShell para agregar eventos de calendario en SharePoint Online

¡PowerShell puede ser una excelente opción si está buscando una manera de agregar eventos a su calendario en línea de SharePoint rápidamente! Aquí está la versión PnP PowerShell para agregar una entrada a un Calendario:


#Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing/"
$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";}

Artículos relacionados