How to call a function in a PowerShell Write-Host expression

$BizTalkHelper = "d:\Scripts\BizTalkHelper.ps1" .$BizTalkHelper # "dot source" the helper library. Write-Host *** BEGIN *** Write-Host $(Get-Date) " Desc:" {GetHostStateDesc 1 } Write-Host $(Get-Date) " Desc:" GetHostStateDesc 2 $result = GetHostStateDesc 1 Write-Host $result 

My functions print "hello" in addition to the switch statement to translate 1 to "Stopped", 2 to "Start Pending", 4 to "Running", etc. .... Therefore, I know that this is not called in the first two cases.

Results:

 *** BEGIN *** 3/29/2013 11:03:34 AM Desc: GetHostStateDesc 1 3/29/2013 11:03:34 AM Desc: GetHostStateDesc 2 hello Function GetHostStateDesc 1 Stopped 
+6
source share
2 answers

It looks like this:

 Write-Host $(Get-Date) " Desc:" $(GetHostStateDesc 1 ) 

I noticed the $() syntax around Get-Date , so if it is a function, I figured it would work for my function, and that happened.

+1
source

Try the following:

 function SayHello {'Hello'} write-host $(SayHello) 

Fingerprints:

 Hello 
+8
source

All Articles