This one command doesn't write output to the screen when running it in a script, but it works when executing it in the PowerShell ISE cli:
$toptenseverity = $csvData | select Severity, Title -Unique | sort Severity -Descending | select -First 11
$toptenseverity
Code:
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
Output:
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:
When I run it from the cli in PS ISE I get this output:
Severity Title
-------- -----
5 YouDon'tNeedToKnowThis
4 YouDon'tNeedToKnowThis
4 YouDon'tNeedToKnowThis
4 YouDon'tNeedToKnowThis
4 YouDon'tNeedToKnowThis
asked Jun 26, 2017 at 15:27
Steve Campbell
931 silver badge7 bronze badges
1 Answer 1
Use:
Write-Output $toptenseverity | Format-Table
This forces the object to be formatted as a table, which is what's going on in the ISE (by default)
answered Jun 26, 2017 at 15:50
G42
10.1k2 gold badges22 silver badges36 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-bash
$toptenseverity | Format-TableorWrite-Output $toptenseverity | Format-Tablegiving you what you want?