【问题标题】:New ListItem with Pnp.PowerShell带有 Pnp.PowerShell 的新 ListItem
【发布时间】:2021-12-23 06:22:37
【问题描述】:

我正在尝试使用 PowerShell 脚本中的 Pnp.PowerShell 模块在 SharePoint Online 列表中创建一个新列表项。这是我的代码和输出:

## ... urls and security creds removed... 
Connect-PnPOnline -Url $km_site -ClientId $clientid -ClientSecret $secret -WarningAction Ignore
[Microsoft.SharePoint.Client.List]$projects_list = Get-PnPList "Projects"
Write-Host $projects_list.Title -ForegroundColor Green
$lci = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation -ArgumentList @()
[Microsoft.SharePoint.Client.ListItem]$new_item = $projects_list.AddItem($lci)
Write-Host $new_item.Id -ForegroundColor Cyan
$new_item["Title"] = $title
$new_item["Project_x0020_Code"] = $code
$new_item["_ExtendedDescription"] = $desc
$new_item["ContentTypeId"] = "0x010097F10B16E4516A4E80FC5C8FABF9BAC400AEEB05A0E486404FA588439EADC25541"
# Write-Host $new_item.FieldValues -ForegroundColor Cyan
$new_item.Update()
# $projects_list.Update()
Write-Host "Created!!" -ForegroundColor Yellow
Write-Host $new_item.Id -ForegroundColor Yellow

输出:

Projects
-1
Created!!
-1

该代码与其他在线示例中的代码相匹配,但未创建列表项,但不会引发错误。

在我的列表中,标题和项目代码是必需的,我使用的是我在管理门户中创建的自定义内容类型,然后包含在“项目”列表中。

【问题讨论】:

    标签: powershell sharepoint-online


    【解决方案1】:

    这是行之有效的解决方案。

    Connect-PnPOnline -Url $km_site -ClientId $clientid -ClientSecret $secret -WarningAction Ignore
    
    [Microsoft.SharePoint.Client.listItem]$list_item = Add-PnPListItem -List "Projects" -ContentType "Project Info" -Values @{"Title" = $title; "_ExtendedDescription"=$desc; "Project_x0020_Code"=$code}
    

    【讨论】:

      猜你喜欢
      • 2021-12-23
      • 1970-01-01
      • 2012-02-07
      • 1970-01-01
      • 2021-04-13
      • 2019-04-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      相关资源
      最近更新 更多