I want to delete all lists with title this and this using PowerShell but getting error
Add-PSSnapin Microsoft.SharePoint.Powershell
Get-SPWebApplication http://ift.tt/1Docp2s | Get-SPSite -Limit All | Get-SPWeb -Limit All | where {$_.Url -Match "crates"} | ForEach-Object {
foreach ($list in $_.Lists) {
if ($list.Title -eq "FruitDocuments")
{
Write-Host($_.Url + "----" + $list.Title + "------" + $list.BaseTemplate)
$list.AllowDeletion = $true
$list.Update()
$list.Delete()
Write-Host("Deleted")
}
elseif ($list.Title -eq "Fruits")
{
Write-Host($_.Url + "----" + $list.Title + "------" + $list.BaseTemplate)
$list.AllowDeletion = $true
$list.Update()
$list.Delete()
Write-Host("Deleted")
}
}
}
Error
http://ift.tt/1zMK5K7
Deleted
Collection was modified; enumeration operation may not execute.
At line:5 char:15
+ foreach ($list in $_.Lists) {
+ ~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException
0 commentaires:
Enregistrer un commentaire