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