#Get the CSV file and connect to the SharePoint list $vessellist = import-csv -Path "C:\Temp\VesselInPortReport.csv" $itemCount = $vessellist.Count; $currentItem = 1; foreach($item in $vessellist) { #Update the progress information Write-Progress -Id 1 -ParentId 0 -Activity "Listing Data In CSV File" -PercentComplete (($currentItem/$itemCount)*100) -Status "Item $currentItem or $itemCount"; $currentItem++; #Write the rows VESSEL_NAME column to the console Write-Host $item.VESSEL_NAME; }
#Get the CSV file and connect to the SharePoint list $vessellist = import-csv -Path "C:\Temp\VesselInPortReport.csv" #Get the list used to import the data to $l = (Get-Spweb "http://corporate").GetList("http://corporate/Lists/VesselsInPort") #Get the lists EmployeeType field (choice) $employeeType = $l.Fields["EmployeeType"] -as [Microsoft.SharePoint.SPFieldChoice] #Loop through the items and add them to the list $r = 1; $itemCount = $vessellist.Count; $currentItem = 1; foreach($item in $vessellist) { Write-Progress -Id 1 -ParentId 0 -Activity "Importing Data From CSV into SharePoint" -PercentComplete (($currentItem/$itemCount)*100) -Status "Adding item $currentItem or $itemCount"; $currentItem++; $ni = $l.items.Add(); #Add the Title, using the rows VESSEL_NAME column $ni["Title"] = $item.VESSEL_NAME; #Add the "Date Recorded" field, using the csv rows "RPT_DATE" column [DateTime]$rd = New-Object System.DateTime; if([DateTime]::TryParse($item.RPT_DATE, [ref]$rd)){ $ni["Date Recorded"] = $rd; } #Add the csv rows "TRIP_NO" column to the new list items "Trip Id" field (SPFieldNumber) [Int64]$tn = New-Object System.Int64; if([Int64]::TryParse($item.TRIP_NO, [ref] $tn)){ $ni["Trip Id"] = $tn; } #Add some other text properties $ni["Flag"] = $item.FLAG; $ni["Agent Name"] = $item.AGENT_NAME; $ni["Current Location"] = $item.CURRENT_LOCATION; #Add user information $ni["employee"] = $w.EnsureUser($item.EMPLOYEE); #In this case, the $item.EMPLOYEE value from the spreadsheet is a persons name. Eg. "Matthew Yarlett" $employeeType.ParseAndSetValue($ni,$item.EMPLOYEE_TYPE); #In this case, the $item.EMPLOYEE_TYPE value from the spreadsheet is valid choice present in the EmployeeType list field. Eg. "Manager" #Update the item $ni.Update() Write-Host ([String]::Format("Added record:{0}",$r)); $r++; }