Powershell Form, get-service with listview

by veroli at 2012-10-04 07:26:43

Hello all,
I have been working on a problem for a few days and think i am close but struggling a bit. I’m new to powershell and .net forms so its a bit of a steep
learning curve.
I’m trying to populate a list view with the output of get-service.
what i want to do is connect to a remote server get a list of services running on the remote machine and then populate a listview control with the headings
Status, Name , Display Name
The server is chosen from a combo box on that is populated with a list of servers so clicking on the server in the combo should update the listview.

I’ve done the work for the combo box fine but the list view is causing me problems. the below code is wrong but i am sure i am getting close but am going round in circles, there are some bits commented out. I think i am getting the loop and the output wrong.
thanks for any help



$servers1 = $objServersListbox.SelectedItem
$services = Invoke-Expression “(get-service -computername $servers1 |out-string)”

foreach ($service in $services)
$item = New-Object System.Windows.Forms.ListViewItem($service)

by Klaas at 2012-10-04 08:03:28
I think you should drop the '| out-string’
When you convert objects to a string, there are no ‘name’,‘displayname’ or ‘status’ properties left.
Does this help:
get-service | select name, displayname, status | Out-GridView ?
by veroli at 2012-10-04 09:02:16
Thanks klaas

It certianly makes sense i will try as soon as am back in front of a shell.
i guess this is the learning experience
by veroli at 2012-10-09 05:06:57
thanks again klaas,
although i didnt use this in my final version it pointed me in the right direction for my own datagrid control.
Now got another problem but thats a different thread i think.