gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:26:12 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com