1

I need to add items to list in MOSS 2007 and item details are present in the CSV file.

Can I use PowerShell/STSADM to add items to the list?

1 Answer 1

2

STSADM doesn't support adding or managing list content. it is primarily for managing the SharePoint server infrastructure and also 2007 version don't have native support with powershell. best method is to use object model in C# but you can also use reflection to call the same dll's in powershell and leverage the same object model with the below code.

Try the below script

$FilePath = "report.csv"
$docliburl="http://myserver/sites/second/test12/Lists/TestList/";
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null;
$site=new-object Microsoft.SharePoint.SPSite($docliburl);
$web=$site.openweb();
$web.Allowunsafeupdates=true;
$list=$web.GetList($docliburl);
$csv_file = Import-Csv $FilePath;
foreach ($line in $csv_file) 
{ 
Write-Output $line.Title;
  $item = $list.Items.Add();
  $item["Title"] = $line.Title;
  $item["Field2"] = $line.Field2;
  $item.Update();
}

Ref: Powershell script to write data into the Sharepoint 2007 list

Your Answer

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

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