【发布时间】:2020-11-19 14:09:51
【问题描述】:
我有一个脚本块/函数,它返回 PSCustomObject 后跟 Write-Host。
我想先得到输出,然后打印写入主机,但我似乎无法弄清楚。
function ReturnArrayList {
param (
[int] $number
)
[System.Collections.ArrayList]$folderList = @()
$folderObject = [PSCustomObject]@{
Name = 'John'
number = $number
}
#Add the object to the array
$folderList.Add($folderObject) | Out-Null
return $folderList
}
$sb = {
param (
[int] $number
)
[System.Collections.ArrayList]$folderList = @()
$folderObject = [PSCustomObject]@{
Name = 'John'
number = $number
}
#Add the object to the array
$folderList.Add($folderObject) | Out-Null
return $folderList
}
ReturnArrayList -number 5
#Invoke-Command -ScriptBlock $sb -ArgumentList 5
Write-Host "This write host should come later"
结果:
This write host should come after
Name number
---- ------
John 5
想要的结果:
Name number
---- ------
John 5
This write host should come after
如何先获取返回结果并打印 write-host 消息? 提前感谢您的帮助!
【问题讨论】:
标签: powershell