Home > Microsoft, Powershell, windows, windows 2012 > Prevent write-output to perform linebreak

Prevent write-output to perform linebreak


Sometimes you want to output some text and append an variable. Problem is that write-output usually performs a linebrak when appending.


$text = "some text."
Write-Output "this is " $text

Output will be:
this is
some text.

There are two ways you can solve this. One is to append the text to the variable before doing write-output. Second is to put the variable inside the quotation marks.


#Example 1
$text = "some text."
$textmessage = "This is " + $text
Write-Output $textmessage

#Example 2
$text = "some text."
Write-Output "this is $($text)"

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: