Integrate do .. until looping in Powershell

@Olaf I change a code with your code. And the OUTPUT is ok, It genarates a random words from the original file. So thank you.

The small problem is that I believe I didn’t replace very correctly your code. I get an error on powershell, even if the output is fine after running the code.

 $fileName = "C:\Folder1\file.txt"

	# Get content of file

  $content = ((Get-Content -Path C:\Folder1\file.txt -Raw ) -split "\s+" | 
    Sort-Object {Get-Random} ) -join ' ' |

  $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
  # Replace words randomly

 ((Get-Content -Path C:\Folder1\file.txt -Raw ) -split "\s+" | 
    Sort-Object {Get-Random} ) -join ' ' |
    Out-File -FilePath C:\Folder1\NewFile.txt

You lack the basic understandig of Powershell fundamentals. Please do yourself a favour and start with learning these basics first. You cannot learn a complex technology like a programming language by guessing or by piecing together some arbirtrary snippets of code you’ve found on the internet and you don’t understand.

@Olaf yes. But this is another way to get starting, as an extra motivation. To guessing or by piecing together some arbirtrary snippets of code. So many good developers they started like this. The important thing is to be motivated, to see that you managed to move something.

anyway, your code was good from the beginning @Olaf there was no need for anything else.

Thank you very much.

 ((Get-Content -Path C:\Folder1\file.txt -Raw ) -split "\s+" | 
     Sort-Object {Get-Random} ) -join ' ' |
         Out-File -FilePath C:\Folder1\NewFile.txt