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 |
Partager