我有2个获取返回信息的命令,我需要将它们合并,以便它们一起输出。有没有办法合并以下命令? TIA
$output = Invoke-Command -Session $s -ScriptBlock {
Get-WinEvent -logname Setup -MaxEvents 1 |
Select-Object TimeCreated, Message, UserId, ContainerLog
}
$output = Get-CimInstance -ClassName win32_operatingsystem |
select csname, lastbootuptime
答案 0 :(得分:3)
这是我平常去的,虽然我确信有更好的方法。
$output = Invoke-Command -Session $s -ScriptBlock { Get-WinEvent -logname Setup -MaxEvents 1 | Select-Object TimeCreated, Message, UserId, ContainerLog }
$output2 = Get-CimInstance -ClassName win32_operatingsystem | select csname, lastbootuptime
#Create a custom object to store the data
[pscustomobject]@{TimeCreated = $output.TimeCreated
Message = $output.Message
UserID = $output.UserID
ContainerLog = $output.ContainerLog
CSName = $output2.csname
LastBoot = $output2.lastbootuptime}