powershell - Add-Content With Condition On One Line -
i'm trying of on 1 line, try doesn't work. tried `b doesn't backspace line above. tried putting condition inline first add-content, didn't work either.
add-content $txtpath "p: $strphone x $strxten | " if ($strmobile -ne $null) { add-content $txtpath "`m: strmobile | " } add-content $txtpath "$strfax"
you can't use multiple add-content calls because each 1 append newline. logged suggestion long time ago nonewline
parameter on add-content. can vote here.
you can use stringbuilder , output contents via add-content or set-content:
$sb = new system.text.stringbuilder [void]$sb.append("p: $strphone x $strxten | ") if ($strmobile -ne $null) { [void]$sb.append("`m: strmobile | ") } [void]$sb.append($strfax) add-content $txtpath $sb.tostring()
Comments
Post a Comment