Add listitems using PowerShell


$weburl = "http://mysharepoint"
$listname = "TestList"
$a = "Text1"
$b = "Text2"
$c = "Text3"

Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue 
$web = Get-SPWeb -Identity $webUrl
$list = $web.Lists[$listname]
$newItem = $list.items.add()
$newitem["Title"] = $a
$newitem["Custom_Column1"] = $b
$newitem["Custom_Column2"] = $c

$newitem.update()


Comments (4)
  1. ASO says:

    Much better :
    $web = Get-SPWeb -Identity $webUrl
    $list = $web.Lists[$listname]
    $newItem = $list.AddItem()
    $newitem["Title"] = $a
    $newitem["Custom_Column1"] = $b
    $newitem["Custom_Column2"] = $c
    $newitem.update()

  2. ASO says:

    Much better :
    $web = Get-SPWeb -Identity $webUrl
    $list = $web.Lists[$listname]
    $newItem = $list.AddItem()
    $newitem["Title"] = $a
    $newitem["Custom_Column1"] = $b
    $newitem["Custom_Column2"] = $c
    $newitem.update()

  3. DenisGRE says:

    simple and clear thanks a lot

Comments are closed.

Skip to main content