I have created a PowerShell Script that looks at a data file, converts it to a CSV file, imports it into SharePoint list.
For the past 5 days, timer job runs the script and creates the list items and the work flow kicks off and completes on every item except the last one.
I cannot reproduce on a test system.
Here is the script.
Script
#Load SharePoint SnapIn
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Set the variables here, Do not modify code below this block
$LogfileName = "C:\Users\Administrator\Desktop\log.txt"
$SourceLocation = "C:\Users\Administrator\Desktop\import"
$TempCSVLocation = "C:\Users\Administrator\Desktop\import\process\temp.csv"
$TargeLocation = "http://picaso.contoso.com/" #SharePoint URL
$TargetList = "Carmike" #SharePoint List
$ArchiveLocation = "C:\Users\Administrator\Desktop\import\archive"
#Set the variables end here
#Update log file that import process started
Add-Content $LogfileName "*********************************" ;
$a=Get-Date
$msg = "Import started at " + $a.ToShortDateString() +" " + $a.ToShortTimeString()
Add-Content $LogfileName $msg
#Read all the files
$fileEntries = [IO.Directory]::GetFiles($SourceLocation);
#If there is atleast one file to be processed
If($fileEntries.Count -gt 0)
{
#Loop through all the files identfied
foreach($fileName in $fileEntries)
{
#To Create a CSV file
$filenamecsv=$fileName -replace ".data",".csv"
import-csv $fileName -delimiter "|" | export-csv $TempCSVLocation -NoTypeInformation
# replace end of line special charecters
(Get-Content $TempCSVLocation) |
Foreach-Object {$_ -replace "\^\*\^", ""} |
Set-Content $TempCSVLocation
#Read the CSV file (CSV File has Column Header)
$CSVData = Import-Csv $TempCSVLocation
#Get the Web
$web = Get-SPWeb -identity $TargeLocation
#Get the Target List
$list = $web.Lists[$TargetList ]
$i=0
#Iterate through each Row in the CSV
foreach ($row in $CSVData)
{
$item = $list.Items.Add();
$item["OrderID"] = $row.OrderID
$item["ColorStatus"] = $row.ColorStatus
$item["ApplicantType"] = $row.ApplicantType
$item["FirstName"] = $row.FirstName
$item["MiddleName"] = $row.MiddleName
$item["LastName"] = $row.LastName
$item["SSN"] = $row.SSN
$item["DOB"] = $row.DOB
$item["Gender"] = $row.Gender
$item["Telephone"] = $row.Telephone
$item["Email"] = $row.Email
$item["TheaterNumber"] = $row.TheaterNumber
$item["InstitutionName"] = $row.InstitutionName
$item["CompleteDate"] = $row.CompleteDate
$item["CreateDate"] = $row.CreateDate
$item["AddressLine1"] = $row.AddressLine1
$item["AddressLine2"] = $row.AddressLine2
$item["County"] = $row.County
$item["City"] = $row.City
$item["State"] = $row.State
$item["Country"] = $row.Country
$item["PostalCode"] = $row.PostalCode
$item.Update()
$i=$i+1;
}
#Move teh file to Archive location
Move-Item $fileName $ArchiveLocation -force
$msg = "Processed File " + $filename +" with " + $i + " records"
Add-Content $LogfileName $msg
}
}
Else{
#Update log file that no files to import
Add-Content $LogfileName "No Files to Import";
}
#Update logfile that Import ended
$a=Get-Date
$msg = "Import ended at " + $a.ToShortDateString() +" " + $a.ToShortTimeString()
Add-Content $LogfileName $msg
Add-Content $LogfileName "*********************************";
Brad Holt