Powershell 在GUI窗体上获取WmiObject-类Win32_产品输出

Powershell 在GUI窗体上获取WmiObject-类Win32_产品输出,powershell,powershell-2.0,powershell-3.0,powershell-4.0,Powershell,Powershell 2.0,Powershell 3.0,Powershell 4.0,嗨,我是Powershell的新手。我正在寻找在GUI表单上获取WmiObject-Class Win32_产品的输出。 提前谢谢 下面是代码,我需要为按钮添加标签,并为每个按钮分配一个功能 标签:卸载 功能:卸载 启动进程Powershell-动词runas#加载Windows窗体程序集[void][System.Reflection.assembly]::LoadWithPartialName(“System.Windows.Forms”)[void][System.Windows.Form

嗨,我是Powershell的新手。我正在寻找
在GUI表单上获取WmiObject-Class Win32_产品的输出。
提前谢谢

下面是代码,我需要为按钮添加标签,并为每个按钮分配一个功能

标签:卸载 功能:卸载 启动进程Powershell-动词runas#加载Windows窗体程序集[void][System.Reflection.assembly]::LoadWithPartialName(“System.Windows.Forms”)[void][System.Windows.Forms.Application]::EnableVisualStyles()#创建GUI$form=New Object System.Windows.Forms.form$form.Size=New Object System.Drawing.Size(920500)$form.form borderstyle=[System.Windows.Forms.FormBorderStyle]::Fixed3D$form.StartPosition=[System.Windows.Forms.FormStartPosition]::中心屏幕$dataGridView=新对象系统.Windows.Forms.dataGridView$dataGridView.Size=新对象系统.Drawing.Size(900400)$button=新对象系统.Windows.Forms.button$button.Location=新对象系统.Drawing.Size(400420)$button.Size=新对象系统.Drawing.Size(75,25)$button.text=“卸载”$form.Controls.Add($button)$form.Controls.Add($dataGridView)#选择适当的列$dataGridView.columns.Insert(0,(新对象系统.Windows.Forms.DataGridViewButtonCell))$dataGridView.ColumnCount=8$dataGridView.ColumnHeadersVisible=$true$dataGridView.Columns[0]。Name=“卸载”$dataGridView.Columns[1]。Name=“描述”$dataGridView.Columns[2]。Name=“IdentificationNumber”$dataGridView.Columns[3]。Name=“Name”$dataGridView.Columns[4]。Name=“供应商”$dataGridView.Columns[5]。Name=“版本”$dataGridView.Columns[6]。Name=“Caption”$dataGridView.Columns[7]。Name=“InstallLocation”$dataGridView.Columns[0]。宽度=40$dataGridView.Columns[1]。宽度=200#获取项目列表#刷新函数gridClick(){$rowIndex=$dataGridView.CurrentRow.Index$columnIndex0=$dataGridView.columnIndex1=$dataGridView.ColumnIndex+2$columnIndex2=$dataGridView.ColumnIndex+3$columnIndex3=$dataGridView.columnIndex5=$dataGridView.ColumnIndex+5#写主机$RowIndex0#写主机$dataGridView.Rows[$rowIndex]。单元格[0]。值写入主机$dataGridView。行[$rowIndex]。单元格[$columnIndex0]。值写入主机$dataGridView。行[$RowIndex1]。值写入主机$dataGridView。行[$RowIndex5]。值#$IdentificationNumber=$dataGridView。行[$rowIndex]。单元格[$ClassKey]。值#$Name=$dataGridView。行[$rowIndex]。单元格[$columnIndex0].value#$classKey='IdentificationNumber=$IdentificationNumber.value,Name=$Name.value,Version=$Version.value'#写入主机$classKey#([wmi]“\$server\root\cimv2:Win32\U Product.$classKey”).uninstall()}$uninstall=$dataGridView.Add#单元格鼠标单击({gridClick})#显示表单[void]$form.ShowDialog()


您可以使用此方法查看GUI网格:

gwmi -Class win32_product | Out-GridView

您还可以获得自定义输出,如XML、CSV、json和其他形式,并使用专用软件进行此操作。

您可以使用此方法查看GUI网格:

gwmi -Class win32_product | Out-GridView

您还可以获得自定义输出,如XML、CSV、json和其他表单,并为此使用特殊软件。

这可能有点过分,但您始终可以创建自定义GUI表单,并在gridview控件中绘制输出,如下所示:

# Load Windows Forms assembly

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
[void][System.Windows.Forms.Application]::EnableVisualStyles()

# Create a GUI

$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(920,500)
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$dataGridView = New-Object System.Windows.Forms.DataGridView
$dataGridView.Size = New-Object System.Drawing.Size(900,400)
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Size(400,420)
$button.Size = New-Object System.Drawing.Size(75,25)
$button.Text = "Refresh"
$form.Controls.Add($button)
$form.Controls.Add($dataGridView)

# Select appropriate columns

$dataGridView.ColumnCount = 7
$dataGridView.ColumnHeadersVisible = $true
$dataGridView.Columns[0].Name = "Description"
$dataGridView.Columns[1].Name = "IdentifyingNumber"
$dataGridView.Columns[2].Name = "Name"
$dataGridView.Columns[3].Name = "Vendor"
$dataGridView.Columns[4].Name = "Version"
$dataGridView.Columns[5].Name = "Caption"
$dataGridView.Columns[6].Name = "InstallLocation"

$dataGridView.Columns[0].width = 240

# Get a list of items

Get-WmiObject -Class Win32_Product | foreach {
    $dataGridView.Rows.Add($_.Description,$_.IdentifyingNumber,$_.Name,$_.Vendor,$_.Version,$_.Caption,$_.InstallLocation) | out-null
}

# Refresh

$button.Add_Click({

    $dataGridView.Rows.Clear()

    start-sleep -s 1

Get-WmiObject -Class Win32_Product | foreach {
    $dataGridView.Rows.Add($_.Description,$_.IdentifyingNumber,$_.Name,$_.Vendor,$_.Version,$_.Caption,$_.InstallLocation) | out-null
}

})

# Add a cell click function

function cellClick(){
$rowIndex = $dataGridView.CurrentRow.Index
$columnIndex = $dataGridView.CurrentCell.ColumnIndex
$value = $dataGridView.Rows[$rowIndex].Cells[$columnIndex].value
write-host $value
}

$dataGridView.Add_CellMouseClick({cellClick})

# Show the form

[void]$form.ShowDialog()

这可能有点过分,但您始终可以创建自定义GUI表单,并在gridview控件中绘制输出,如下所示:

# Load Windows Forms assembly

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
[void][System.Windows.Forms.Application]::EnableVisualStyles()

# Create a GUI

$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(920,500)
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::Fixed3D
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$dataGridView = New-Object System.Windows.Forms.DataGridView
$dataGridView.Size = New-Object System.Drawing.Size(900,400)
$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Size(400,420)
$button.Size = New-Object System.Drawing.Size(75,25)
$button.Text = "Refresh"
$form.Controls.Add($button)
$form.Controls.Add($dataGridView)

# Select appropriate columns

$dataGridView.ColumnCount = 7
$dataGridView.ColumnHeadersVisible = $true
$dataGridView.Columns[0].Name = "Description"
$dataGridView.Columns[1].Name = "IdentifyingNumber"
$dataGridView.Columns[2].Name = "Name"
$dataGridView.Columns[3].Name = "Vendor"
$dataGridView.Columns[4].Name = "Version"
$dataGridView.Columns[5].Name = "Caption"
$dataGridView.Columns[6].Name = "InstallLocation"

$dataGridView.Columns[0].width = 240

# Get a list of items

Get-WmiObject -Class Win32_Product | foreach {
    $dataGridView.Rows.Add($_.Description,$_.IdentifyingNumber,$_.Name,$_.Vendor,$_.Version,$_.Caption,$_.InstallLocation) | out-null
}

# Refresh

$button.Add_Click({

    $dataGridView.Rows.Clear()

    start-sleep -s 1

Get-WmiObject -Class Win32_Product | foreach {
    $dataGridView.Rows.Add($_.Description,$_.IdentifyingNumber,$_.Name,$_.Vendor,$_.Version,$_.Caption,$_.InstallLocation) | out-null
}

})

# Add a cell click function

function cellClick(){
$rowIndex = $dataGridView.CurrentRow.Index
$columnIndex = $dataGridView.CurrentCell.ColumnIndex
$value = $dataGridView.Rows[$rowIndex].Cells[$columnIndex].value
write-host $value
}

$dataGridView.Add_CellMouseClick({cellClick})

# Show the form

[void]$form.ShowDialog()

哪个Powershell版本?标记特定版本意味着需要只在该版本上工作的解决方案。由于PS2/3/4非常不同,标记所有这些可能都不相关。无论如何,您想要什么样的GUI表单?Out GridView是否足够好?感谢您的回复。.Out GridView对我来说是公平的,但Matt Szadziul ans是我正在寻找的。哪个Powershell版本?标记特定版本意味着需要只在该版本上工作的解决方案。由于PS2/3/4非常不同,标记所有这些可能都不相关。无论如何,你要找什么样的GUI表单?Out GridView
足够好吗?谢谢你的回复..Out Gridview对我来说是公平的,但Matt Szadziul ans是我要找的。很高兴我能帮上忙:)嘿,Matt,你能帮我从网格中读取所选单元格的单个数据吗?我修改了脚本,需要在其中选择项目并卸载应用程序。我一直在读取所选项目。嗨,Deep:)我添加了一个函数,用于检索当前列和当前行的单元格值。如果通过ISE启动脚本,所选值将写入控制台(变量值)。希望有帮助:)很高兴我能帮助:)嘿,马特,你能帮我从网格中读取所选单元格的单个数据吗。我已经修改了脚本,需要在其中选择项目并卸载应用程序。我一直在阅读所选项目。嗨,Deep:)我添加了一个函数,用于检索当前列和当前单元格的单元格值行。如果您通过ISE启动脚本,所选值将写入控制台(变量值)。希望有帮助:)