locked
Powershell script to write data into the Sharepoint 2007 list RRS feed

  • Question

  • Hi Folks

    I am sharepoint adminsitrator and need a powershell script which will read the values from the file and write into the sharepoint list.

    basically everyday we have a file from the SQL Dba and i wana write those file into the sharepoint so that every one can view it. 

    thanks

    --ws


    SharePoint administrator, MCTS,MCITP
    Friday, November 12, 2010 3:47 PM

Answers

  • The script below loads CSV file to SharePoint list. If you need load more fields just simple add those fields in 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();
    $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();
    }


    Oleg
    • Marked as answer by Porter Wang Thursday, November 18, 2010 7:22 AM
    Monday, November 15, 2010 4:51 PM

All replies

  • If you have MOSS 2007 Enterprise you can use BDC to get data directly from SQL. It will work without a development.
    Oleg
    Friday, November 12, 2010 8:07 PM
  • Nopes, we have only MOSS standard version.

     

    thanks

    -ws


    SharePoint administrator, MCTS,MCITP
    Saturday, November 13, 2010 2:40 AM
  • The script below loads CSV file to SharePoint list. If you need load more fields just simple add those fields in 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();
    $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();
    }


    Oleg
    • Marked as answer by Porter Wang Thursday, November 18, 2010 7:22 AM
    Monday, November 15, 2010 4:51 PM