如何在Powershell的花括号中添加新行?
代码:
"1. Files are `n different" #This is Successful
{"2. Files are `n different" } #This fails
结果:
1. Files are
different
"2. Files are `n different"
我正在尝试为上下文运行if语句。
if(Compare-Object -ReferenceObject $(Get-Content $OriginalScript) -DifferenceObject $(Get-Content $NewFilename))
{$Database + " Files are different `n"}
答案 0 :(得分:4)
花括号用于表示脚本块。
dynamic_cast
如果您这样做
PS C:\> ({"2. Files are `n different"}).GetType().Name
ScriptBlock
您只是在输出脚本块的内容,而脚本本来是要执行的:
PS C:\> {"2. Files are `n different"}
"2. Files are `n different"