从脚本vs cli运行时,没有来自Powershell命令的输出

时间:2017-06-26 15:27:06

标签: powershell

这个命令在脚本中运行时不会将输出写入屏幕,但在PowerShell ISE cli中执行它时它会起作用:

$toptenseverity = $csvData | select Severity, Title -Unique | sort Severity -Descending | select -First 11
$toptenseverity

代码:

Write-Host "`r`nTop 10 most severe vulnerabilities:"
$toptenseverity = $csvData | select Severity, Title -Unique | sort Severity -Descending | select -First 11
$toptenseverity
Write-Host "Trying again to write output of toptenseverity using write host toptenseverity:"
Write-Host $toptenseverity
Write-Host "Trying again to write output of toptenseverity using write output toptenseverity:"
Write-Output $toptenseverity

输出:

Generating P1 report. Please wait...

Total P1 count:    352
Severity 5 total:  11
Severity 4 total:  16
Severity 3 total:  325

Top 10 most severe vulnerabilities:

Trying again to write output of toptenseverity using write host toptenseverity:
@{Severity=5; YouDon'tNeedToKnowThis} @{Severity=4; Title=YouDon'tNeedToKnowThis} @{Severity=4; Title=YouDon'tNeedToKnowThis
} @{Severity=4; Title=YouDon'tNeedToKnowThis} @{Severity=4; Title=YouDon'tNeedToKnowThis} 
Trying again to write output of toptenseverity using write output toptenseverity:

当我从PS ISE中的cli运行它时,我得到了这个输出:

Severity Title                                                                                  
-------- -----                                                                                  
5        YouDon'tNeedToKnowThis                                                  
4        YouDon'tNeedToKnowThis
4        YouDon'tNeedToKnowThis                                    
4        YouDon'tNeedToKnowThis                             
4        YouDon'tNeedToKnowThis                               

1 个答案:

答案 0 :(得分:1)

使用:

Write-Output $toptenseverity | Format-Table 

这会强制将对象格式化为表格,这是ISE中正在进行的操作(默认情况下)