Converting the Windows Script Host WriteLine Method
Definition: Sends a string with a newline character to an output stream.
WriteLine
In Windows Script Host the WriteLine method enables you to write data (plus a carriage return-linefeed) to the console window. In Windows PowerShell, you don’t need any method calls or specialized cmdlets in order to accomplish this same task. Instead, you can write a string to the command window simply by specifying the string to be written. For example, this command writes the value This is a test to the command window:
"This is a test"
Likewise, you can echo back the value of a variable simply by specifying the variable name:
$a
Or, if you prefer, use the Write-Host cmdlet to echo data to the screen:
Write-Host "This is a test."
So if you don’t need the Write-Host cmdlet why would you ever want to even use the Write-Host cmdlet? Well, Write-Host does give you a few additional capabilities when it comes to formatting your output. For example, this command, along with the –foreground and –background parameters – enables you to output red text on a yellow background:
Write-Host "This is a test" -foreground red -background yellow
Alternatively, try the following example, which writes three items – Alpha, Beta, Gamma – to the screen, using the three dots to separate the individual items:
Write-Host "Alpha", "Beta", "Gamma" -separator " ... "
Fun, huh?
See conversions of other Windows Script Host methods and properties.
Return to the VBScript to Windows PowerShell home page