Questions tagged [write-host]

66 questions
1
vote
1 answer

How to echo predefined variable from PowerShell command line?

I'm able to Write-Host a custom variable from PowerShell command line, but predefined variables are not working with same way. What is proper way to echo a predefined variable. Write-Host $path works. Write-Host $PSScriptRoot does not. Here is my…
1
vote
4 answers

What is the difference in result by write-host and write-output?

I am new to PowerShell and while doing some code I came through this thing. While I use Write-Host and Write-Output to perform the same query, I get different results: PS> Write-Output $PSVersionTable …
Kaushal
  • 41
  • 1
  • 6
1
vote
2 answers

Subtract/Add days to a predefined date using Write-Host

I am trying to display milestones. I tried below but I get an error that displays Method invocation failed because [System.String] does not contain a method named 'AddDays'. I have predefined $lastmodified in a previous line and it is 12/28/2015…
ShanayL
  • 1,217
  • 2
  • 14
  • 29
0
votes
0 answers

Powershell - Can I use the output of write-host as a command?

I am using a command line tool called GAMADV-XTD3 to automate a lot of things on my google workspace instance such as email signatures, google drive permissions - etc. Recently I was asked to also set out of office messages for people that email our…
0
votes
0 answers

PowerShell send "write-host" or "write-output" also to a file

I wrote a script which works, but the output is long enough that it would take a large console buffer to capture it all and paste it into a file to save. I would like to be able to send the result strings both to the screen and to a file. In the…
0
votes
0 answers

Passing Write-Host color parameter to a function

I want to pass a color parameter to a function to display a message in different colors function WriteLogColor { param ([String]$Msg, $Color) $TimeStamp = Get-Date -Format "dd/MM/yy HH:mm:ss" Write-Host "[$TimeStamp] $Msg"…
StartingPS
  • 11
  • 2
0
votes
2 answers

Using Powershell if/then to create different exit codes based on file count in a folder

I'm trying to create a script that counts every file in a folder. The count part on its own works fine but I'm looking to make it output an exit code based off of the count for use in an automation tool. value | message | exit code =15 …
Todd
  • 1
0
votes
0 answers

PowerShell Write-Host $_ Produces no Output Inside a Loop

$ll = @("a","b","c"); ForEach ($e in $ll) {Write-Host $_} I've spent too much time on this already and I'm tired of searching and fiddling. Who wants to make me feel silly by explaining why this PowerShell code produces no output? No errors. Just 3…
Dr_Snooz
  • 1
  • 1
0
votes
3 answers

CRLF using powershell write-host

I am trying to output a log file to a variable and use that variable as Body on a Send-MailMessage. The problem is that all CRLFs in the variable are missing in the output. ex. $Body = get-content .\TTT.txt $body Test Test1 Test2 write-host…
tfonias74
  • 136
  • 9
0
votes
1 answer

Formatting problem with the MENU after the first iteration of a Do-Until loop

The first time my PSMenu function is called, the formatting appears correct. After the first loop iteration, the formatting somewhat randomly changes. It seems local to the first few "columns" of text. If you type enough $input sometimes the…
Zero
  • 1
  • 1
0
votes
1 answer

Powershell-Function Write-Host output won't print with color Black

Morning Folks, I've taken the Add-Border function from jdhitsolutions and have been messing around with it to add coloring to the output instead of piping the output to Write-Host like he's shown in some examples. Now I've gotten it to work with…
Fitzgery
  • 558
  • 5
  • 14
0
votes
0 answers

Create folder on remote computer using PowerShell

The intention is to create a folder on a remote computer C drive. I'm trying to run this: $stageSvrs | %{ Invoke-Command -ComputerName $_ -ScriptBlock { $setupFolder = "c:\Support\test1" Write-Host "Creating Support Folder" …
0
votes
1 answer

Print on PowerShell Console in different format depending on different Condition

I have written a logging function for my PowerShell Script, which will log the Input to the file, at the same time also display the same onto the output screen. While displaying the output on the screen, depending on different matching conditions,…
0
votes
1 answer

How to indent command output in powershell

I am trying to present a ping command output in a nice indent... But, can't seem to format it properly.... I want an output like this : Result: Pinging google.com [216.58.208.110] with 32 bytes of data: Reply from 216.58.208.110:…
Mr. E
  • 457
  • 1
  • 5
  • 20
0
votes
1 answer

Why does write-host output to transcript but write-information does not?

This one is confusing me and wondered if anyone could shed some light on this, maybe also answer 2 parts with this one example? I have a Powershell script I run like a batch file and I have it output values it has captured from a separate file out…
Adam Lacey
  • 103
  • 1
  • 11