我想将多个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
感谢您的建议!
答案 0 :(得分:0)
你可以在Powershell V3中使用Out-GridView
:
$cert,$dot3sv,$eap | Out-GridView
Out-GridView类似于PropertyGrid,但其优点是它只适用于PowerShell对象(psobject)。