The csv is about a gig and has over 1million rows. I'm attempting to split it into 5. The first 4 take about 18 hours - the 5th never happens ( or I havnt been patient enough) my pc will just sit in a sleep mode because it wont unlock.
function Split-Csv{
[CmdletBinding()]
Param(
[Parameter(Mandatory)]
[string]$FilePath,
[Parameter()]
[string]$Delimiter=',',
[Parameter(Mandatory)]
[string]$TargetFolder,
[Parameter(Mandatory)]
[string]$Name,
[Parameter(Mandatory)]
[int]$NumberOfFiles
)
try{
if(-not (Test-Path $TargetFolder)){
New-Item -Path $TargetFolder -ItemType Directory
}
$csvData=Import-Csv -Path $FilePath -Delimiter $Delimiter
$startRow=0
$numberOfRowsPerFile=[Math]::Ceiling($csvData.count/$NumberOfFiles)
$counter=1
while($startRow -lt $csvData.Count){
$csvData | Select-Object -Skip $startRow -First $numberOfRowsPerFile | Export-Csv -Path "$TargetFolder\$Name-$counter.csv" -NoTypeInformation -NoClobber
$startRow+=$numberOfRowsPerFile
$counter++
}
}catch{
Write-Error $_.Exception.Message
}
}
Split-Csv -FilePath "C:\temp\2018.csv" -Delimiter ',' -TargetFolder "C:\temp\Split" -Name "Split" -NumberOfFiles 5