1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #Parameters
$content = Get-Content "mon_fichier_source_avec_path"
#$lenght = $content.Count
#Pour tester sur une seule clé
$lenght = 75
$fichier = "file_name"
$path = "path_name"
#Gestion de la Première ligne
$i = 0
$ligne = $content[0]
$NumTable = $ligne.substring(0,3)
New-Item -Path $path -Name ($fichier + "." + $NumTable + ".txt") -ItemType file -value $ligne
#Initialisation du $match et de la Deuxieme ligne
$match = $NumTable
$i = 1
#Creation des fichiers
do {
$ligne = $content[$i]
$NumTable = $ligne.substring(0,3)
if ($NumTable -eq $match) {
$ligne | Out-File -FilePath ($fichier + "." + $NumTable + ".txt") -Append -Encoding UTF8 -Force -Verbose
}
else {
New-Item -Path $path -Name ($fichier + "." + $NumTable + ".txt") -ItemType file -Value $ligne
}
$i = $i + 1
$NumTable = $match
}while($i -lt $lenght) |