Diviser Exporter de gros files CSV via Powershell

Comme tout le monde le sait, Excel a obtenu des lignes maximales 1048574. Ma question est la suivante: lorsque la ligne maximale est atteinte, passez à un nouveau file CSV. J'ai essayé quelque chose, pas de chance, je ne peux pas le comprendre.

$RootFolder = Get-Content "c:\DRIVERS\myfile.txt" foreach ($arrayOfPaths in $RootFolder){ $csv = $arrayofPaths -replace '^\\\\[^\\]+\\([^\\]+)\\([^\\]+).*', 'C:\output\Company_name_${1}_${2}.csv' Get-ChildItem $arrayOfPaths -Recurse | Where-Object {$_.mode -match "d"} | ForEach-Object { $path = $_.FullName Get-Acl $path | Select-Object -Expand Access | Select-Object @{n='Path';e={$path}}, IdentityReference, AccessControlType, FileSystemRights | Export-Csv $csv -Append -NoType } } 

Dernière mise à jour :

 $RootFolder = Get-Content "c:\DRIVERS\myfile.txt" foreach ($arrayOfPaths in $RootFolder){ $csv = $arrayofPaths -replace '^\\\\[^\\]+\\([^\\]+)\\([^\\]+).*', 'C:\output\Company_name_${1}_${2}.csv' $csvIndex = 1 $maxRows = 1000000 $rowsLeft = $maxRows Get-ChildItem $arrayOfPaths -Recurse | Where-Object {$_.mode -match "d"} | ForEach-Object { #$csv = $_.FullName -replace '^\\\\[^\\]+\\([^\\]+)\\([^\\]+).*', 'C:\output\Company_name_${1}_${2}.csv'# <- construct CSV path here $path = $_.FullName $thisCSV = Get-Acl $path | Select-Object -Expand Access | Select-Object @{n='Path';e={$path}}, IdentityReference, AccessControlType, FileSystemRights | ConvertTo-Csv if ($thisCSV.count -lt $rowsLeft) { $thisCSV | Export-Csv $csv -append -noType $rowsLeft -= $thisCSV.count } else { $thisCSV[0..($rowsLeft - 1)] | Export-Csv $csv -append -noType $csvIndex++ $csv = $csv -replace '\.csv$', "$csvIndex.csv" if ($thisCSV.count -gt $rowsLeft) { $thisCSV[$rowsLeft..($thisCSV.count - 1)] | Export-Csv $csv -append -noType } $rowsLeft = $maxRows - ($thisCSV.count - $rowsLeft) } } } 

Do ConvertTo-Csv dans une variable temporaire, additionnez sa propriété .Count jusqu'à ce que le sharepoint partage soit atteint, puis divisez le tableau CSV sur un nouveau file avec un nouveau nom qui sera utilisé à partir de ce point.

Voici un exemple simplifié qui suppose qu'aucun CSV ne peut dépasser 1000000 lignes.

 $csv = ............. $csvIndex = 1 $maxRows = 1000000 $rowsLeft = $maxRows ........... $thisCSV = Select-Object ........ | ConvertTo-Csv if ($thisCSV.count -lt $rowsLeft) { $thisCSV | Export-Csv $csv -append -noType $rowsLeft -= $thisCSV.count } else { $thisCSV[0..($rowsLeft - 1)] | Export-Csv $csv -append -noType $csvIndex++ $csv = $csv -replace '\.csv$', "$csvIndex.csv" if ($thisCSV.count -gt $rowsLeft) { $thisCSV[$rowsLeft..($thisCSV.count - 1)] | Export-Csv $csv -append -noType } $rowsLeft = $maxRows - ($thisCSV.count - $rowsLeft) }