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
| #Compte le nombre de lignes dans le Fichier A
write-host = "Ecrivez le fichier à compter"
$FichierA = read-host
$measure = Get-Content $FichierA
$lines = ($measure | Where-Object {$_ -ne ""}).Count
echo "line count is: ${lines}"
write-host = "Ecrivez le fichier à copier"
$FichierB = read-host
write-host = "Ecrivez les variables à ajouter"
$Variable1 = read-host
$Variable2 = read-host
gc -path $FichierB | foreach {$_ -replace "simplement", "$Variable1 "}
gc -path $FichierB | foreach {$_ -replace "facilité", "$Variable2"}
$idmax = $lines # nombre maximun de sauvegarde (de 1 à $lines)
$Source = "$env:H:\"
#$destination = "H:\cript\$env:UserName"
$destination = "H:\cripts\Sauvegardes\$env:UserName"
# a la premiere execution du script création des repertoires sauvegardes
1..$idmax | ForEach-Object {
If (-not (Test-Path "$destination\Sauvegarde$_") -and -not (Test-Path "$destination\_Sauvegarde$_")) {
new-Item -ItemType directory -Path "$destination\Sauvegarde$_" | new-Item -ItemType file -Path "$destination\Sauvegarde$_\FichierB$_.txt"
Write-Host "----> Sauvegarde $_ cree" -ForegroundColor Green
}
} |
Partager