powershell - format-default :集合尚未初始化。PowerShell + SharePoint Online 错误
问题描述
我的 PowerShell 脚本有问题。脚本从 SharePoint 列表中删除记录,然后从 csv 中添加新记录。基本上,当我逐行运行脚本时,一切正常。但是当我尝试运行整个事情时,我得到了这个错误:
format-default :集合尚未初始化。它尚未被请求或请求尚未执行。可能需要明确请求。+ CategoryInfo : NotSpecified: (:) [format-default], CollectionNotInitializedException + FullyQualifiedErrorId : Microsoft.SharePoint.Client.CollectionNotInitializedException,Microsoft.PowerShell.Commands.FormatDefaultCommand
这是我的代码:
$list_modified = 'list_name'
$filename = "C:\.......\file.csv"
# Purge existing records in list
$records = Get-PnPListItem -List $list_modified -PageSize 500
# make sure fields in list have corresponding field in csv and same data type
Get-PnPField -List $list_modified
# purge list
foreach ($record in $records)
{
Write-Host "Removing Id " $record.Id
Remove-PnPListItem -List $list_modified -Identity $record.Id -Force
}
Get-PnPField -List $list_modified
$records = Get-PnPListItem -List $list_modified -PageSize 500
$records | measure
# Import csv
$csv_data = Import-CSV -Path $filename -Delimiter `t
foreach ($row in $csv_data) {
Add-PnPListItem -List $list_modified -Values @{
"Title" = $row.'name';
"uuid" = $row.'uuid';
"name" = $row.'name';
"short_description" = $row.'short_description';
"logo_url" = $row.'logo_url';
"homepage_url" = $row.'homepage_url';
"category_groups_list" = $row.'category_groups_list';
"category_list" = $row.'category_list';
"total_funding_usd" = $row.'total_funding_usd';
"last_funding_on" = $row.'last_funding_on'
}
}
我究竟做错了什么?请帮忙!
谢谢!马切伊
解决方案
谷歌搜索以下内容会发现许多类似的问题:
format-default : 集合尚未初始化
来自:https ://github.com/pnp/PnP-PowerShell/issues/799#issuecomment-618926331
尝试将您的语句返回到变量中。
做这个
$item = Add-PnPListItem -List $list -ContentType "Project" -Values $Values**
和
$item = Set-PnPListItem -List $list -Identity $targetItem.Id -Values $Values**
推荐阅读
- java - 不一致地获取 ConnectionCloseException
- django - Django 通道图像保存、TextField 或 ImageField
- vscode-remote - 无法通过 SSH 通过终端在 VS Code 中打开文件
- python - VS Code:如何调试使用 Connexion 的 Flask 应用程序?
- c++ - 使用 constexpr 变量禁用函数模板特化或重载
- c++ - 检测到物体后的像素轮廓(无凸包)
- javascript - 如何在 vue.js 中从 api 渲染数据
- c# - ignite 是否会在过期后删除缓存?
- rust - 如何打印函数调用时间线?
- typescript - 为 ES5 和 ES6 目标编译的 JavaScript 库