9
$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 

我的函数打印“你好”,此外还有一个 switch 语句将 1 转换为“已停止”、2 转换为“开始挂起”、4 转换为“正在运行”等......所以我知道在前两种情况下它没有被调用.

结果:

*** 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
4

2 回答 2

12

试试这个:

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

这打印:

Hello
于 2013-03-29T16:12:45.997 回答
5

看起来是这样的:

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

我注意到$()周围的语法Get-Date,所以如果它是一个函数,我猜它会在我的函数上工作,而且确实如此。

于 2013-03-29T16:10:06.010 回答