Friday, August 9, 2013

Get or Delete SharePoint List Item using Powershell

Below script will be helpful to get the SharePoint List Item with given Item ID.

Inputs:
  • Site URL
  • List Name
  • Item ID

if ((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Out-null
$web = Get-SPWeb http://sitename:portnumber/
$listName = "Discussion"
$list = $web.Lists[$listName]
$items = $list.Items | Where {$_["ID"] -eq 741}
foreach($item in $items)
{
$item["ID"]
$item["Title"] = "Using Powershell"
$item.Update()
#Function comes here #
}


Add the below line inside above foreach to delete the List Item,
$item.Delete()



Related Posts Plugin for WordPress, Blogger...