I have got a Sharepoint list. I updeted it in job everyday and everyday refresh by powershell. I have got some column on this sharepoint list. One of this column called [nazwazdarzenia]. And the code which works for today great was:

    # Delete existing List Data, If not required remove this line
$Items = $list.GetItems()
$Items | ForEach-Object{

But now, I want to delete everyrecord without record which have got in column [nazwazdarzenia] =! "Szkolenie". So delete all records without records with column [nazwazdarzenia] not equal "Szkolenie". What If I should add to PowerShell to dellete all records without "Szkolenie". Please help.

2 Answers 2


Use the following code:

$list.Items | ? {$_["nazwazdarzenia"] -ne "Szkolenie"} | % {$list.GetItemById($_.Id).Delete()}
  • Great hack code :)
    – Grzegorz Z
    Feb 19, 2016 at 13:05
  • Work brilliant :)
    – Grzegorz Z
    Feb 19, 2016 at 13:05
$web = Get-SPWeb <SharePoint URL>
$listName = "LIST NAME HERE"
$list = $web.Lists[$listName]
$items = $list.Items | Where {$_["nazwazdarzenia" ] -ne "Szkolenie"}
foreach($item in $items)
Write-Host "Deleting " $item.ID

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.