Wednesday, 19 November 2014

delete data from lists using power shell script in SharePoint

delete data from lists using power shell script

write-host "This will delete data, type YES to continue"
$retval = read-host
if ($retval -ne "YES")
{
    write-host "exiting - you did not type yes" -foregroundcolor green
    exit
}
write-host "continuing"

$web = get-spweb http://ggn-sp10:5555/
$list = $web.lists | where {$_.title -eq "ComplianceDetails"}
Write-host "List $($list.title) has $($list.items.count) entries"
$items = $list.items
foreach ($item in $items)
{
    Write-host "  Say Goodbye to $($item.id)" -foregroundcolor red
    $list.getitembyid($Item.id).Delete()
}