如何在Powershell中获取Invoke-Expression的返回值

问题描述 投票:0回答:1

这是我的代码

$result = Invoke-Command -Session $session -FilePath $ps1

如何获得 $ps1 给出的结果?

该函数的代码应该给出如下所示的 true false 结果:

function MyFunction{
#some code
if ($JobStatus -like "Running")
        {
        $result = $false
            Write-Host "Gresit" -foreground Red
        }
    else 
        {
        $result = $true
            Write-Host "Corect" -foreground Green
        }
}
powershell return-value invoke-command
1个回答
0
投票

使用 return 代替 Write-Host。

例如: if ($JobStatus - 就像“正在运行”) { $结果 = $假 返回“格雷西特” } 别的 { $结果 = $true 返回“正确” } }

© www.soinside.com 2019 - 2024. All rights reserved.