I'm writing a PowerShell file that creates a batch file having variables between texts that includes quotation marks.
Please see below the script so that you can understand what I mean.
$addnewcomputerhere = Read-Host -Prompt 'Input new computername'
$addnewusernamehere = Read-Host -Prompt 'Input new username'
Write-Output 'powershell -Command "(gc sourcechangeme.txt) -replace ''newcomputername'', '''$addnewcomputerhere'''| Out-File source1changeme.txt"' | Add-Content edittextdone.bat
Write-Output 'powershell -Command "(gc sourcechangeme.txt) -replace ''newusername'', '''$addnewusernamehere'''| Out-File source1changeme.txt"' | Add-Content edittextdone.bat
Running the script edittextdone.bat
should then look like this:
powershell -Command "(gc sourcechangeme.txt) -replace 'newcomputername', 'thecomputernamethathasbeengivenonprompt'| Out-File source1changeme.txt"
powershell -Command "(gc sourcechangeme.txt) -replace 'newusername', 'theusernamethathasbeengivenonprompt'| Out-File source1changeme.txt"
Instead of that it looks like this:
powershell -Command "(gc sourcechangeme.txt) -replace 'newcomputername', '
thecomputernamethathasbeengivenonprompt'| Out-File source1changeme.txt"
powershell -Command "(gc sourcechangeme.txt) -replace 'newusername', '
theusernamethathasbeengivenonprompt'| Out-File source1changeme.txt"
My problem is that the variables start new lines.
I was searching for any advice and went through this with no luck.
I've also read about -NoNewline
, but couldn't figure out how to use it correctly.