Powershell: mélange les mots
salut. Mon code Powershell doit mélanger tous les mots de file.txt Ma fonction Remplacer ne change pas trop de mots entre eux. Donc, je crois que je dois intégrer un code en boucle * do .. while *. Quelqu'un peut-il m'aider?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| $fileName = "C:\Folder1\file.txt"
$newfilename = "C:\Folder1\newfile.txt"
# Get content of file
$content = Get-Content -Path $fileName -Raw -Encoding UTF8
$words = (((($content.Split(" ")).Replace(".","")).Replace(",","")).Replace("`n",""))
#Define function
Function Create-Words {
$script:word1 = Get-Random -InputObject $words
$script:word2 = Get-Random -InputObject $words
Write-Host "First word: " $script:word1 -ForegroundColor Red # output word1
Write-Host "Second word: " $script:word2 -ForegroundColor Cyan # output word2
}
# Execute function
Create-Words
# Replace words randomly
$content.Replace("$word1", "$word2") | Out-File -FilePath "$newfilename" -force |