Questions tagged [write-host]
66 questions
18
votes
3 answers
How does one output bold text in powershell?
I got a Powershell script that do some automatic procedures, I use a "Write-Host" at the end of each one of them to tell the technical user that step is finished, but I realize is kind of hard to read and keep track so, ¿Is there a way to output a…

Haroldo Payares Salgado
- 361
- 1
- 4
- 20
16
votes
3 answers
Does PowerShell has something like "echo off" and "echo on" trigger?
cmd/batch file could turn on and turn off "echo".
So in PowerShell, I have a bunch of "write-host" output, I want somewhere to turn on / off write-host for debugging convenience.
Does PowerShell has such a function?

vik santata
- 2,989
- 8
- 30
- 52
6
votes
2 answers
How to determine if Write-Host will work for the current host
Is there any sane, reliable contract that dictates whether Write-Host is supported in a given PowerShell host implementation, in a script that could be run against any reasonable host implementation?
(Assume that I understand the difference between…

jimbobmcgee
- 1,561
- 11
- 34
6
votes
2 answers
Write text in orange with Write-Host
I'm wondering if it's possible to write some coloured-text in orange with Write-Host (or with another PowerShell Cmdlet).
It seems Orange is not an available color for the -ForegroundColor parameter, but commands like Write-Warning are able to…

Jérôme
- 26,567
- 29
- 98
- 120
5
votes
1 answer
Why does Write-Host not work when run in a powershell job?
Sorry if I'm being a dumb powershell noob, but what's wrong with jobs apparently being unable to write to the terminal? And how can I fix that?
# test.ps1
function myjob {
Write-Host "Hello, World!" # doesn't show
}
Start-Job -Name MyJob…

Binkan Salaryman
- 3,008
- 1
- 17
- 29
5
votes
3 answers
Powershell piping to variable and write-host at the same time
Hello all and thanks for your time in advance;
I'm running into a slight issue.
I'm running a command and piping it into a variable so i can manipulate the output.
$variable = some command
this normally works fine but doesn't output what's…

Razorx
- 53
- 1
- 1
- 5
4
votes
1 answer
Write-Host with background colour fills the entire line with background colour when window is resized in powershell
eg, if you execute this command in a powershell session
write-host 'hello' -ForegroundColor 'red' -BackgroundColor 'cyan'
resizing the window causes the background colour to fill the entire line:
I have tested this in Windows Terminal, Windows…

Plastikfan
- 3,674
- 7
- 39
- 54
3
votes
2 answers
How do I write-host a single property of an element in a powershell array?
I queried Office365 for a list of all users that match the displayName of Chris.
I'd like to prompt the user for which Chris they want to select. In doing so I have the following for..each code
$tmpUserOffice = Get-MsolUser -SearchString…

Ran Dom
- 315
- 5
- 13
3
votes
1 answer
Capture Write-Host output and exit code from Invoke-Command on a Remote System
I have a script located on a remote system.
On the server "web12" under C:\tmp\hgttg.ps1:
Write-Host "Don't Panic"
exit 42
I invoke this script from my local box (both systems running v4.0) using Invoke-Command:
$svr = "web12"
$cmd =…

Derek_6424246
- 237
- 3
- 12
3
votes
1 answer
Write-Host cannot parse variable's property
It's quite weird that Write-Host doesn't seem to parse variable's property.
PS C:\Users\x> $v=@{item1="kkk";item2="aaa"}
PS C:\Users\x> $v.Keys|%{$v.Item($_)}
kkk
aaa
PS C:\Users\x> Write-Host "$v.Count elements"
System.Collections.Hashtable.Count…

Immanuel Kant
- 517
- 3
- 8
3
votes
1 answer
Output message with variable part to TeamCity build log from PowerShell
I know that one can output messages to TeamCity build logs via specially decorated Write-Host:
write-host "##teamcity[message text='Prepearing backup folder']"
What if I need the message to contain a value of a variable as well.
I've tried the…

Maxim V. Pavlov
- 10,303
- 17
- 74
- 174
2
votes
1 answer
PowerShell write-host background color continuing past the code
this is from VS code, also happens in PowerShell 7.3 in Windows Terminal
the code is this:
write-host "text text text" -ForegroundColor Magenta -BackgroundColor white
that's just for a test, but it happens a lot more often when write-host is…
user20682592
2
votes
1 answer
Variables that contains the color of a text in PowerShell
Is it possible to store in a variable the color of a text? I tried this but it doesn't work:
$format1 = "-ForegroundColor White"
$format2 = "-BackgroundColor Black"
Write-Host "Example" $format1 $format2
It returns:
"Example -ForegroundColor White…

Dstr0
- 95
- 2
- 13
2
votes
3 answers
Powershell Get Child Item Exclude doesn't work in current directory
As I mentioned in question, this seems like bug in Powershell engine.
When I try to print the files in the current directory(where the said powershell script is also present) by excluding some file-types(extensions), it doesn't print anything. For…

Vicky Dev
- 1,893
- 2
- 27
- 62
2
votes
2 answers
redirecting test-path output to text file
The txt file is just a bunch of UNC paths, i am trying to get a list of UNC paths from this text file put into another text file after the test-path is validated. it shows the validated paths on screen but the text file does not populate.
$cfgs =…

200mg
- 503
- 1
- 10
- 24