【发布时间】:2018-04-06 06:44:13
【问题描述】:
您好,执行此操作时出现此错误。你能帮帮我吗?
foreach($item in $items)
{
$created = $item["Created"]
if ($created -lt $days)
{
Write-Host "Title - " $item["Title"] "Created - " $item["Created"]
$test = $item["ID"]
write-host $test
$item["ID"].DeleteObject()
#$item[].DeleteObject()
}
}
$context.ExecuteQuery()
方法调用失败,因为 [System.Int32] 不包含方法 命名为“删除对象”。 在 F:\JoshScript\deletebydate.ps1:46 char:2 + $item["ID"].DeleteObject() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
【问题讨论】:
-
你试过
$item.DeleteObject()吗?您可以添加创建$items的行吗?它是什么类型/对象? -
是的,我也试过了,但它只删除了第一项。
-
删除 listitems.Title - 测试已创建 - 2018 年 4 月 2 日上午 7:05:58 2 集合已修改。枚举操作可能无法执行。在 F:\JoshScript\deletebydate.ps1:34 char:10 + foreach($item in $items) + ~~~~~~ + CategoryInfo : OperationStopped: (:) [], InvalidOperationException + FullyQualifiedErrorId : System.InvalidOperationException 项目是从列表中删除。
标签: powershell sharepoint-online