I need to delete all the items present in the list view on the click of the "delete all" action button.
foreach($selectedItem in $allData) {
$item = Get-Item -Path "master:" -ID $selectedItem.ID
$item | Remove-Item
$allData.Remove($selectedItem)
}
But it deletes only the first item in the list. Maybe it is throwing some error in $allData.Remove($selectedItem)
.
When I try to execute it in ISE with test data in $allData
, it throws below error:
Exception calling "Remove" with "1" argument(s): "Collection was of a fixed size."
Please suggest how to resolve this?