Export (0) Print
Expand All
Expand Minimize

Converting the Windows Script Host Write Method

Windows PowerShell

Definition: Sends a string to an output stream.


The Write method enables you to output data to the console window without appending a carriage return-linefeed (newline) character to the end of that output. What does that mean? Well, suppose you call the Write method and write the following to the screen:


Now suppose you call the Write method a second time, this time writing DEF to the screen. What’s your console window going to look like? You got it:


Because there’s no carriage return-linefeed the new data is simply tacked onto the end of whatever else is on the current line.

And yes, that is kind of nice, isn’t it?

In Windows PowerShell you can accomplish this same feat by using the Write-Host cmdlet and the –noNewLine parameter. For example:

Write-Host "ABC" -noNewLine

Not very impressed? Then try the following script, which calls Write-Host several times, including four instances when the –noNewLine parameter is used:

Write-Host "ABCDEFG" -noNewLine
Write-Host "HIJKLMNO" -noNewLine
Write-Host "PQRSTUV" -noNewLine
Write-Host "WXYZ" -noNewLine

When you run the preceding script you should see the following appear on screen:


Here’s another example, one that uses the “escape character” `b (Backspace). Give it a try and see what happens:

Write-Host "5" -noNewLine
Start-Sleep 1
Write-Host "`b4" -noNewLine
Start-Sleep 1
Write-Host "`b3" -noNewLine
Start-Sleep 1
Write-Host "`b2" -noNewLine
Start-Sleep 1
Write-Host "`b1" -noNewLine
Start-Sleep 1

See conversions of other Windows Script Host methods and properties.
Return to the VBScript to Windows PowerShell home page

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft