从脚本与cli运行时,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                               

使用:

Write-Output $toptenseverity | Format-Table 

这迫使对象被格式化为一个表格,这是ISE中发生的事情(默认情况下)

链接地址: http://www.djcxy.com/p/30249.html

上一篇: No output from Powershell command when run from script vs cli

下一篇: Windows "run" command doesn't find powershell anymore