Questions tagged [write-host]

49 questions
11
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,525
  • 5
  • 24
  • 47
8
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…
5
votes
0 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,341
  • 8
  • 28
5
votes
1 answer

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
  • 24,687
  • 27
  • 88
  • 114
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 =…
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
  • 9,743
  • 14
  • 66
  • 164
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,219
  • 1
  • 18
  • 40
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
  • 423
  • 6
  • 17
2
votes
2 answers

Write-Host and Log on one line?

I'm very new to PowerShell, and self-teaching myself it at that. My question is can you have 'write-host' and 'log-write' on the same line, to run as one action? What I have is this: Write-Host "Node Id is $nodeProps["NodeID"]" LogWrite "Node Id…
Spence Rico
  • 23
  • 1
  • 3
2
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…
1
vote
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
  • 2,722
  • 5
  • 32
  • 47
1
vote
0 answers

No output in PowerShell Plugin of Jenkins

I'm using the Jenkins Plugin (not pipeline) Windows Powershell for my scripts. Everything is fine, if the script is written directly into the Command-Window. But for some more complex operations I'm using a .ps1-File located on my SCM, since all…
MarcoB
  • 43
  • 5
1
vote
1 answer

Piping output from Write-Host to other command

I have this script that finds files based on certain cafeterias and write their path using Write-Host. Now, I would like to pipe all of these file paths, and do stuff with those files. Basically the first script is like…
Peter Poulsen
  • 411
  • 4
  • 7
1
vote
0 answers

Powershell problematic without working code changes

I have several points of working code that now no longer works. Here is a block of code: if ($day -eq 01) { echo "The Day of Days" } else { echo "Not Today" } I get the following result: At D:\PS_Scripts\Archive-Log.ps1:88 char:15 + …
roachd
  • 11
  • 1
1
vote
2 answers

Function with String Message, echos to screen, change the color of message

Good Morning all, SOLVED Both responses worked hand in hand. Big Thanks to Scepticalist and Wasif Hasan for the examples!! I have a logging function that has a message parameter. Through the function it writes the message with a text color of green.…
Fitzgery
  • 113
  • 8
1
2 3 4