Question

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?

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top