0

我想将几个 Windows 服务的状态显示到System.Windows.Forms.PropertyGrid中。

我尝试使用SelectedObject而不是SelectedObjects但我不知道如何修复输出。

$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)

这是我当前的表单输出:

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

如何获得以下显示?

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

感谢您的建议!

4

1 回答 1

0

您可以Out-GridView在 Powershell V3 中使用:

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

Out-GridView 类似于 PropertyGrid,但它的优点是它只适用于 PowerShell 对象 (psobject)。

于 2013-10-15T21:47:47.107 回答