1

I want to take input in powershell but I want it to be multi-line, if I try to do this with read-host it doesn't work because when I press enter it submits. I tried this with `n as well as \n but nothing works

$test = read-host Enter Stuff

Enter stuff: 

Test `n test \n test

$test

Test `n test \n test

Please help

Nico Nekoru
  • 2,402
  • 1
  • 15
  • 32
Nikola Johnson
  • 319
  • 3
  • 9

1 Answers1

0
while (1) 
  {
    read-host | set r
    set test -value ($test+"`n"+$r)
    if (!$r) {break}
  }
$test = $test.trim()

This will take a multi-line input. If you want to allow line breaks, I would just add

$test = $test.replace("<br>","")

Which would make <br> as a carriage return, but you can change it to anything you's like like so:

$test = $test.replace("Whatever you want","")
$test = $test.replace("CRLF","")
$test = $test.replace("Break","")

What it does is that it keeps on taking new read-hosts until one of the lines is blank then it stops. Each individual line is $r and the whole input is $test

Nico Nekoru
  • 2,402
  • 1
  • 15
  • 32