Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Display Get-Process with ListView

$
0
0

I'm experimenting with PowerShell and trying to learn more about it. So far I've grasped the basics and am now trying to use it in conjunction PrimalForms to create a GUI. What I want to do is, with the press of a button, neatly display all currently running processes, similarly to the task manager.

I would like it to have three columns, one for the process' name, one for its CPU load and a third for the ID.

$sampleForm = New-Object System.Windows.Forms.Form
$sampleForm.Width = 300
$sampleForm.Height = 300

$listView = New-Object System.Windows.Forms.ListView
$listView.View = 'Details'
$listView.Width = 300
$listView.Height = 300

$listView.Columns.Add('ID')
$listView.Columns.Add('Process name')
$listView.Columns.Add('CPU Load')

Get-Process | %{
    Add-ListViewItem -ListView $listView `
        -Items $_.ID`
        -SubItems $_.ProcessName, $_.CPU
}

$sampleForm.Controls.Add($listView)
[void] $sampleForm.ShowDialog()

So far I've done it less elegantly with the above code, it works by itself but not when I combine it with the code generated by PrimalForms. Together with the code from PrimalForms the ListView output will only output all the processes, but not create the columns. How can I create these columns and properly place everything where it should be? Any help is greatly appreciated!



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>