Link to home
Start Free TrialLog in
Avatar of NicksonKoh
NicksonKohFlag for Singapore

asked on

Delete all records in a Picture Library

Hi,

I wrote a simple powershell script to delete all the records in a SharePoint 2007 Picture Library.

$sc = New-Object Microsoft.SharePoint.SPSite($webURL)
$web = $sc.OpenWeb()
$srcList = $web.Lists[$srcListName]

## Loop through the items in the Document Library
$srcItemCnt = 0
foreach($srcItem in $srcList.items)	{
	Write-Host $srcItem["ID"]
	$srcItem.Delete()
}

$web.Dispose()
$sc.Dispose()

Open in new window


But I am getting error "An error occurred while enumerating through a collection: Collection was modified; enumeration operation may not exec
ute.."

Can advise where I am wrong?
SOLUTION
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial