这有效但我想在每一行之后添加一个新的空白行,例如`n
$objAverage = New-Object PSObject
$objAverage | Add-Member Noteproperty -name FirstName-value $FirstName
$objAverage | Add-Member Noteproperty -name LastName -value $LastName
$objAverage | Add-Member Noteproperty -name Office -value $Office
$objAverage | fl
提前致谢
答案 0 :(得分:2)
您可以使用.Net' Environment.NewLine属性将换行符附加到字符串中,
$objAverage = New-Object PSObject
$objAverage | Add-Member Noteproperty -name FirstName -value $("Winston"+[Environment]::NewLine)
$objAverage | Add-Member Noteproperty -name LastName -value $("Smith"+[Environment]::NewLine)
$objAverage | Add-Member Noteproperty -name Office -value $("Room 101"+[Environment]::NewLine)
$objAverage | fl
# Output:
FirstName : Winston
LastName : Smith
Office : Room 101
PS C:\>
答案 1 :(得分:0)
一种野蛮的方式:
$FN = "Jack"
$LN = "Black"
$Of = "HR"
$firstName = @"
$FN
"@
$LastName = @"
$LN
"@
$Office = @"
$Of
"@
$objAverage = New-Object PSObject
$objAverage | Add-Member Noteproperty -name FirstName-value $FirstName
$objAverage | Add-Member Noteproperty -name LastName -value $LastName
$objAverage | Add-Member Noteproperty -name Office -value $Office
$objAverage | fl
答案 2 :(得分:0)
如果您只想修改输出而不修改实际数据,可以执行以下操作:
($objAverage | fl | Out-String) -replace "(.`r`n)", "`$1`r`n"
上面将列表输出转换为字符串,并将换行符(CR-LF)附加到所有非空行。