SharePoint Tech Blog

11/08/2009

Add item to SharePoint list and approve using Powershell

Filed under: SharePoint — Tags: , , — kctnpblog @ 7:31 am

This specific example is about adding an item to the site directory list and approving it automatically. However the same code can be used to add an item to any list in SharePoint and approve it.

This code requires the SharePoint Powershell Profile to be loaded beforehand

$web=Get-SPWeb -url "http://moss/sitedirectory";
$list=$web.Lists["Sites"];
$newitem=$list.items.Add();
$newitem["Title"]="Project One";
$newitem["Description"]="Test Site for Project One";
$newitem["URL"]="http://mossprojects/projectone, Project One URL";
$newitem.ModerationInformation.Status= [Microsoft.SharePoint.SPModerationStatusType]::Approved;
$newitem.ModerationInformation.Comment="Auto approved";
$newitem.Update();
$web.Dispose();

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.