如何使用 SharePoint Online Management Shell 添加 SharePoint 列表项?

问题描述 投票:0回答:1

我尝试使用 PnP PowerShell 使用“Add-PnPListItem”命令添加 SharePoint 列表项。

我需要使用 SharePoint Online Management Shell 添加 SharePoint 列表项。

建议 SharePoint Online Management Shell 命令添加共享点列表项....

list powershell sharepoint powershell-2.0 sharepoint-online
1个回答
0
投票

请尝试此 SharePoint Online 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"
#Set Config Parameters
$SiteURL="https://Crescent.sharepoint.com"
$ListName="Tasks"
 
Try {
    #Get 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 List
    $List=$Ctx.Web.Lists.GetByTitle($ListName)
  
    #sharepoint online powershell add list item
    $ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation 
    $ListItem = $List.AddItem($ListItemInfo)
     
    #Set Column Values
    $ListItem["Title"] = "Project Darwin"
 
    #Set People Picker Field value
    $AssignedToUser = $Ctx.web.EnsureUser("[email protected]")
    $ListItem["AssignedTo"] = $AssignedToUser
     
    #Set Date Fields
    $ListItem["StartDate"] = "01/07/2015"
    $ListItem["DueDate"] = "01/08/2015"
     
    #Set Percentage Field
    $ListItem["PercentComplete"] = "0.2" #20%
 
    #add item to sharepoint online list powershell
    $ListItem.Update()
    $Ctx.ExecuteQuery()
  
    Write-host -f Green "New Item has been added to the List!"
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
} 

参考:SharePoint Online:使用 PowerShell 添加新列表项

© www.soinside.com 2019 - 2024. All rights reserved.