I have a weekly export in CSV format that contains employee information from another system.
I would like to loop through the CSV and upload X number of documents to a permanent document library on a default template from a template library elsewhere with each new document having a unique name i.e. Employee1, Employee2 that I then need mapped to the corresponding row on the CSV, amount depents on total rows.
I then need to update the metadata of each new document to the corresponding row on the CSV file.
The script below only works if there is on row on the CSV.
Thanks to http://www.sharepointdiary.com/2012/10/bulk-upload-files-to-sharepoint-using-powershell.html
#Configuration Variables
$SiteURL="http://sharepointdev/eregister"
$LibraryName="employees"
$FilesPath="\\sharepointdev\DavWWWRoot\Lists\Templates\"
$TemplateName="Employee Agreement"
$CSVFilePath="e:\weeklyexport\employees.csv"
#Get the Web
$Web = Get-SPWeb $SiteURL
#Get the Target Document Library to upload
$Library = $Web.GetFolder($LibraryName)
#Get CSV file contents
$CSVData = Import-CSV -path $CSVFilePath
#Count CSV rows
[int]$LinesInFile = 0
$reader = New-Object IO.StreamReader $CSVFilePath
while($reader.ReadLine() -ne $null){ $LinesInFile++ }
write-host "Number of records to process:"$LinesInFile
#Iterate through each Row in the CSV
Foreach ($Row in $CSVData)
{
write-host "Uploading File:"$Row.Name
#Get the File from local disk
$SourcePath= Join-Path $FilesPath -ChildPath $Row.Name
$SourceFile = (Get-ChildItem $SourcePath).OpenRead()
#Set Metadata Hashtable For the file
$Metadata = @{"FullName" = $Row.Full_Name;"Department" = $Row.Department;"Position" = $Row.Position;"StartDate" = $Row.Start_Date}
#upload the file
$uploaded = $Library.Files.Add($Row.Name+$LinesInFile, $SourceFile, $Metadata, $TRUE)
}
Can anyone help to further progress this script to handle multiple records?
Any help is appreciated
Thanks