Passing new line from command line to PowerShell

How to pass a new line character from the command line to PowerShell?

// MyScript.ps1:
[CmdletBinding()]
Param(
    [Parameter()] $Param
)

Write-Host $Param

// Command line (not PowerShell - cmd.exe!)
powershell.exe -File MyScript.ps1 -Param "First`nSecond"

      

Does not work. Also using command line newline character \n

doesn't work. So how do I pass the newline to the command line?

+3


source to share


3 answers


A workaround would be to use any other character, eg. \n

at the command line and replace it in PowerShell:

$x = $param.Replace("\n", "`n")

      



This works, however, this is of course a hack and not my preferred solution.

+4


source


In First Line◙Second Line

there is a special character like First Line◙Second Line

.



+1


source


You need a carriage return and a line feed:

`r`n

      

So this should work:

powershell.exe -File MyScript.ps1 -Param "First`r`nSecond"

      

0


source







All Articles