Question

I'd like to display the status of several Windows Services into a System.Windows.Forms.PropertyGrid.

I tried using SelectedObject instead of SelectedObjects but I cannot figure how to fix the output.

$certificate = (Get-ChildItem cert:\LocalMachine\My\ -ErrorAction SilentlyContinue).Subject

$hostname = New-Object PSObject 
$hostname | Add-Member Noteproperty sName "Hostname"
$hostname | Add-Member Noteproperty sValue (hostname)
$hostname | Add-Member Noteproperty sReadOnly $True

$cert = New-Object PSObject
$cert | Add-Member Noteproperty sName "Certificate"
$cert | Add-Member Noteproperty sValue ($certificate -imatch $hostname.sValue)

$dot3sv = New-Object PSObject
$dot3sv | Add-Member Noteproperty sName "Dot3svService"
$dot3sv | Add-Member Noteproperty sValue ((Get-Service -Name dot3svc).Status -eq "Running")

$eap = New-Object PSObject
$eap | Add-Member Noteproperty sName "EAPService"
$eap | Add-Member Noteproperty sValue ((Get-Service -Name EapHost).Status -eq "Running")


$PropertyGrid1 = New-Object System.Windows.Forms.PropertyGrid
$PropertyGrid1.Dock = [System.Windows.Forms.DockStyle]::Fill
$PropertyGrid1.SelectedObjects = @($cert, $dot3sv, $eap)

This is my current Form output:

[+] Default Text I'd like to change
  [0]          |  @{sName="Certificate",sValue=True}
  [1]          |  @{sName="Dot3svService",sValue=True}
  [2]          |  @{sName="EAPService",sValue=True}

How can I get the following display?

[+] Status
  Certificate     |  True
  Dot3svService   |  True
  EAPService      |  True

Thanks for your advices!

Was it helpful?

Solution

You could just use Out-GridView in Powershell V3:

$cert,$dot3sv,$eap | Out-GridView

Out-GridView is similar to a PropertyGrid but has the advantage that it just works with PowerShell objects (psobject).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top