1
I have a PowerShell Script, which contain $frcnt
Variable, it will gives a tow condition array:
1. Values
: Name of process (without duplicates).
2. Keys
: How many duplicates process.
i want to show each above array in HTML table such as:
Keys Values
chrome 10
explorer 5
firefox 7
here's my wrong syntax:
$GetCon = Get-NetTCPConnection
$GName = foreach ($process in $GetCon) {
$processName = (Get-Process -Id $process.OwningProcess).ProcessName
$process | Add-Member -NotePropertyName ProcessName -NotePropertyValue $processName -PassThru
}
$gnmcnt = $GetCon | select -ExpandProperty ProcessName
$frcnt=@{}
$gnmcnt | % {if (!($frcnt.ContainsKey($_))) {$frcnt.Add($_,1)} else {$frcnt.Item($_)=$frcnt.Item($_) +1}}
$TableBody,$StrBody=""
$frcnt | ForEach-Object {
$TableBody+="<tr><td>$($_.Keys)</td> <td>$($_.Values)</td></tr>"
}
$Body =@"
<table>
<th>Process</th><th>Count</th>
$TableBody
</table>
"@
$Head = "<Style> body {Background-color: lightblue; } table {background-color: white; margin: 5px; float: left; top: 0px; display: inline-block; padding:5px; border: 1px solid black} tr:nth-child(odd) {background-color: lightgray} </style>"
$HTML = ConvertTo-Html -Body $Body -Head $Head
$HTML | Out-File -filepath "C:\temp\test.html" -Force
Invoke-Item "C:\temp\test.html"
Again: I want to each result show's in with count values. thanks.
I don't have time to look where in the code it goes wrong and how to fix it, but I can tell you, you are not working with an array, there's only one result. – LPChip – 2017-01-20T22:31:53.500
@LPChip you'r right, in fact as you see in the image result, it show's all process in one table row <tr>. why? i don't know why! please could you show me an simple example to show all results in each tr? thanks – SchoolforDesign – 2017-01-20T22:37:08.367