Reputation: 1539
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(900,600)
$ColName = @{Expression={$_.CSNAME};Label="SERVER NAME"},
@{Expression={$_.Caption};Label="OS NAME"; width =25},
@{Expression={$_.OSArchitecture};Label="OS TYPE"}
$out = Get-WmiObject Win32_OperatingSystem -ComputerName "suman-pc" |
Format-Table -HideTableHeaders $ColName
list = New-Object System.Collections.ArrayList
$list.Insert($out)
$dataGridView = New-Object System.Windows.Forms.DataGridView -Property @{
Size=New-Object System.Drawing.Size(800,400)
ColumnHeadersVisible = $true
DataSource = $list
}
$form.Controls.Add($dataGridView)
$form.ShowDialog()
The above code is generating the below error. my objective is collect OS name for multiple system, and present it in datagrid format
New-List : Cannot bind parameter 'MarkerOffset'. Cannot convert value "System.Collections.ArrayList" to type "System.Double". Error: "Input string was not in a correct format." At C:\Users\Suman\AppData\Local\Temp\4abe9ca5-3580-4c58-918b-9f1f721c1f32.ps1:10 char:19 + list = New-Object System.Collections.ArrayList + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [New-List], ParameterBindingException + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,AutoGenerateCmdlets669798327.NewListCommand Cannot find an overload for "Insert" and the argument count: "1". At :\Users\Suman\AppData\Local\Temp\4abe9ca5-3580-4c58-918b-9f1f721c1f32.ps1:11 char:1 + $list.Insert($out) + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodCountCouldNotFindBest
Upvotes: 1
Views: 459
Reputation: 3236
I have found a couple of reasons here.
First you dont want to use Format-Table since it goes only as representive output.
Second you using wrong method, you should using $list.Add() instead of $list.Insert()
Here's fixed code:
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$form = New-Object System.Windows.Forms.Form
$form.Size = New-Object System.Drawing.Size(900,600)
$ColName = @{Expression={$_.CSNAME};Label="SERVER NAME"},
@{Expression={$_.Caption};Label="OS NAME";},
@{Expression={$_.OSArchitecture};Label="OS TYPE"}
$out = Get-WmiObject Win32_OperatingSystem -ComputerName "suman-pc" | Select-Object $ColName
$list = New-Object System.Collections.ArrayList
[void]$list.Add($out)
$dataGridView = New-Object System.Windows.Forms.DataGridView -Property @{
Size=New-Object System.Drawing.Size(800,400)
ColumnHeadersVisible = $true
DataSource = $list
}
$form.Controls.Add($dataGridView)
$form.ShowDialog()
Upvotes: 1