我需要存储命令输出以便稍后在函数中将其作为变量传递
#This works
[scriptblock]$command = {Get-EventLog system -newest 1 | Format-List}
$command.Invoke()
但是当我尝试写入主机时它失败了
#This works
[scriptblock]$command = {Get-EventLog system -newest 1 | Format-List}
Write-Host $command.Invoke()
带输出
Microsoft.PowerShell.Commands.Internal.Format.FormatStartData Microsoft.PowerShell.Commands.Internal.Format.GroupStartData Microsoft.PowerShell.Commands.Internal.Format.FormatEntryData Microsoft.PowerShell.Commands.Internal.Format.GroupEndData Microsoft.PowerShell.Commands.Internal.Format.FormatEndData
我尝试使用它的脚本行是
$SMTPMessage = New-Object System.Net.Mail.MailMessage('UserName [email protected]','[email protected]','subjectText',($command.Invoke()) )
谢谢