Powershell:如何简单地将日期输出到DataGridView

时间:2012-04-25 19:25:28

标签: arrays powershell datagridview wmi

我在这里遇到了一个真正的问题。

拿这段代码:

Get-WmiObject Win32_ComputerSystemProduct -ComputerName summer | Select Vendor,Version,Name,IdentifyingNumber,UUID

我正在尝试将上面的Get-WMI对象传输到Datagridview,其数据输出与您通过控制台直接运行时看到的相同。

出于某种原因,它一直被输出到DatagridView中,其中Vendor,Version等列显示了目录路径或我不想要的一些数据。

在控制台中自行尝试,我希望它能够输出。

这是我正在使用的datagridview:

$arrayt = New-Object System.Collections.ArrayList
  $global:target_active_d = Get-WmiObject Win32_ComputerSystemProduct -ComputerName $target_hostname.text | get-member Vendor,Version,Name,IdentifyingNumber,UUID
  $arrayt.AddRange($target_active_d)
  $target_output.DataSource = $arrayt

请帮忙

谢谢!

2 个答案:

答案 0 :(得分:1)

尝试这样的事情:

$arrayt = New-Object System.Collections.ArrayList
  $global:target_active_d = Get-WmiObject Win32_ComputerSystemProduct -ComputerName $target_hostname.text | Select-Object Vendor,Version,Name,IdentifyingNumber,UUID
  $arrayt.Add($target_active_d)
  $target_output.DataSource = $arrayt

答案 1 :(得分:0)

此代码显示了您在Get-WmiObject代码段中选择的字段:

Clear-Host
$objForm = New-Object System.Windows.Forms.Form
$objForm.AutoSize = $True
$current_output = New-Object System.Windows.Forms.DataGridView 
$current_output.AutoSize = $True
$objForm.Controls.Add($current_output) 
$arraylist = New-Object System.Collections.ArrayList
$arraylist.Add((Get-WmiObject Win32_ComputerSystemProduct -ComputerName "." | Select-Object Vendor,Version,Name,IdentifyingNumber,UUID))
$current_output.DataSource = $arraylist
[void]$objForm.Activate()
[void]$objForm.ShowDialog()
[void]$objForm.Dispose()