powershell - 如何在Powershell Write-Host语句中调用函数

标签 powershell

$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 

除了将1转换为“Stopped”,将2转换为“Start Pending”,将4转换为“Running”等的switch语句外,我的函数还显示“hello”。
因此,我知道在前两种情况下不会调用它。

结果:
*** 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

最佳答案

试试这个:

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

打印:
Hello

关于powershell - 如何在Powershell Write-Host语句中调用函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15706873/

相关文章:

powershell - 在 powershell WebClient 和 FileStream 中使用相对路径

c# - 具有运行空间模拟的 MVC Controller

xml - Powershell 在 XML 中添加字符

powershell - 带有变量的 Get-ADUser 过滤器失败

powershell - 在Powershell中,参数和参数有什么区别?

.net - 如何以编程方式区分/控制 Azure 内部流量与出站流量?

powershell - EntityReference中的DynamicsCRM QueryExpression条件

datetime - 更改时区后 Powershell 显示旧时间

azure - 权限不足,无法完成操作 - Azure Active Directory

git - 具有Git命令错误处理的Powershell-在外部程序的非零退出代码时自动中止