none
write in one line RRS feed

  • General discussion

  • I have this (Powershell 4.0) :

    write $a " is online."

    But the output is:

    server1

    is online.

    I would like everything in one line.

    As far as I see, write-host with -nonewline would make the trick, but it does not in my case. I have this output:

    Microsoft.PowerShell.Commands.Internal.Format.FormatStartData  is offline

    I have also tried: Write "$a is offline" , but then I again get: Microsoft.PowerShell.Commands.Internal.Format.FormatStartData  is offline

    I have also tried "&&", "||" to concatenate strings, but no luck again.

    Thanks in advance.

     

     


    Luis Olías.

    • Changed type Bill_Stewart Friday, July 27, 2018 8:37 PM
    • Moved by Bill_Stewart Friday, July 27, 2018 8:37 PM This is not break/fix forum
    Thursday, May 24, 2018 9:43 AM

All replies

  • Hi, 

    If you replace write with write-host it will write it out on the same line.

    $a = "server1"
    write-host $a "is online."


    Kind Regards Don

    Thursday, May 24, 2018 10:05 AM
  • It's alway recommended to use full cmdlet names and parameter names. "write" is the standard alias for the cmdlet Write-Output. And the behaviour you see is the normal behaviour of the cmdlet Write-Output. ;-)

    Best regards,

    (79,108,97,102|%{[char]$_})-join''

    Thursday, May 24, 2018 11:11 AM
  • Hi,

    You could always create a new variable with the updated line and then write that out.

    $a = "server1"
    $nfo = "$a is online"
    Write-Output $nfo


    Kind Regards Don

    Thursday, May 24, 2018 11:25 AM
  • Hi, 

    If you replace write with write-host it will write it out on the same line.

    $a = "server1"
    write-host $a "is online."


    Kind Regards Don

    I already tried that Donovan, and I got this line:

    Microsoft.PowerShell.Commands.Internal.Format.FormatStartData  is offline

    I have tried almost anything I could think of, really.

    THANKS.


    Luis Olías.

    Thursday, May 24, 2018 1:12 PM
  • Hi,

    You could always create a new variable with the updated line and then write that out.

    $a = "server1"
    $nfo = "$a is online"
    Write-Output $nfo


    Kind Regards Don

    I am having again this message: Microsoft.PowerShell.Commands.Internal.Format.FormatStartData  is offline

    There must be something wrong with the script or with my Powershell because it happened the same with Donovan's suggestion (above)


    Luis Olías.

    Thursday, May 24, 2018 1:18 PM
  • The code is correct. It would seem that PowerShell is broken in some way. You will need to remediate that.

    -- Bill Stewart [Bill_Stewart]

    Thursday, May 24, 2018 2:09 PM