How do I output text without a newline in PowerShell?

前端 未结 17 2308
独厮守ぢ
独厮守ぢ 2020-12-07 15:13

I want my PowerShell script to print something like this:

Enabling feature XYZ......Done

The script looks something like this:



        
17条回答
  •  鱼传尺愫
    2020-12-07 16:06

    It may not be terribly elegant, but it does exactly what OP requested. Note that the ISE messes with StdOut, so there will be no output. In order to see this script work it can't be run within the ISE.

    $stdout=[System.Console]::OpenStandardOutput()
    $strOutput="Enabling feature XYZ... "
    $stdout.Write(([System.Text.Encoding]::ASCII.GetBytes($strOutput)),0,$strOutput.Length)
    Enable-SPFeature...
    $strOutput="Done"
    $stdout.Write(([System.Text.Encoding]::ASCII.GetBytes($strOutput)),0,$strOutput.Length)
    $stdout.Close()
    

提交回复
热议问题