2

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
3
  • $toptenseverity | Format-Table or Write-Output $toptenseverity | Format-Table giving you what you want? Commented Jun 26, 2017 at 15:30
  • Write-Output $toptenseverity | Format-Table worked! Thank you. Now, how do I mark your reply as the answer? Commented Jun 26, 2017 at 15:46
  • Great! I've submitted properly as answer (comments can't be accepted - just upvoted of flagged) Commented Jun 26, 2017 at 15:51

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.