How do I output text without a newline in PowerShell?

前端 未结 17 2236
独厮守ぢ
独厮守ぢ 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 15:50
    $host.UI.Write('Enabling feature XYZ.......')
    Enable-SPFeature...
    $host.UI.WriteLine('Done')
    
    0 讨论(0)
  • 2020-12-07 15:50

    desired o/p: Enabling feature XYZ......Done

    you can use below command

    $a = "Enabling feature XYZ"

    Write-output "$a......Done"

    you have to add variable and statement inside quotes. hope this is helpful :)

    Thanks Techiegal

    0 讨论(0)
  • 2020-12-07 15:50

    You can absolutely do this. Write-Output has a flag called "NoEnumerate" that is essentially the same thing.

    0 讨论(0)
  • 2020-12-07 15:52

    Yes, as other answers have states, it cannot be done with Write-Output. Where PowerShell fails, turn to .NET, there are even a couple of .NET answers here but they are more complex than they need to be.

    Just use:

    [Console]::Write("Enabling feature XYZ.......")
    Enable-SPFeature...
    Write-Output "Done"
    

    It is not purest PowerShell, but it works.

    0 讨论(0)
  • 2020-12-07 15:53

    There seems to be no way to do this in PowerShell. All of the previous answers are not correct, because they do not behave the way Write-Output behaves but more like Write-Host which doesn't have this problem anyway.

    The closes solution seems to use Write-Host with the -NoNewLine parameter. You can not pipe this which is a problem generally, but there is a way to override this function as described in Write-Host => Export to a file, so you can easily make it accept the parameter for an output file. This is still far from a good solution. With Start-Transcript this is more usable, but that cmdlet has problems with native applications.

    Write-Outputsimply can't do what you need in a general context.

    0 讨论(0)
  • 2020-12-07 15:56

    Write-Host -NoNewline "Enabling feature XYZ......."
    

    0 讨论(0)
提交回复
热议问题