Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6971465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:50:37+00:00 2026-05-27T16:50:37+00:00

I wrote several Powershell scripts which deploy software for a client. I used Write-Host

  • 0

I wrote several Powershell scripts which deploy software for a client. I used Write-Host to output a lot of information so that the progress of the deploy can be watched and they call this from one of their deploy application using Start-Transcript to capture this output.

However, they also need to be able to call some of these scripts from another application which can only capture output from stdout. This means that Write-Host won’t work there since it outputs only to the console or host and doesn’t get directed to stdout (correct?)

My thought was that I could change the code to use Write-Out instead, except that this causes another problem. Since I use functions and since functions in Powershell “return” everything that goes to stdout to the caller that would likely screw up any of my code that retrieves output from a function.

Is there a way to direct output to stdout from a function without it going to the calling code as the output of the function itself? Here is an example of the problem:

function Test-Output ([int]$number) {
    Write-Output "This is a string"
    return $number
}

[int]$someNumber = Test-Output 10

$someNumber

If you run the code above you’ll see an error because Powershell is trying to assign “This is a string” to the integer $someNumber. If you change the variable to a string then it will capture the full output of the function (This is a string 10) and assign it to the variable.

Thanks for any suggestions that you can give!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T16:50:37+00:00Added an answer on May 27, 2026 at 4:50 pm

    Try this.

    function Add-Numbers {
        param (
            [double] $FirstNumber,
            [double] $SecondNumber
        )
    
        Write-Host "Hello World"
    
        return ($FirstNumber + $SecondNumber)
    }
    
    $result = Add-Numbers 1 2
    
    #Write-Host "Result is $result"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a software which wrote and includes within several components each of which
I wrote some c# code, which implements the transfer of several functions. I used
I wrote a composite web control that is used in several web applications. If
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I have several functions that I wrote and I use regularly on my servers,
I have several small open-source projects that I wrote. All my attempts to find
I have a structure which I need to populate and write to disk (several
I have several embedded linux systems that I want to write a 'Who's Online?'
I have several lists in Matlab that I want to write to the same
I wrote a CLR class with several methods, which are linked as functions in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.