Create UI using PowerShell - DataGrid

by jagan at 2013-04-06 02:43:28

Gurus, I am stuck here with datagrid. please please help!!

What am I trying to do:

I am trying to build a SQL Server Inventory for my company using powershell. Idea is to read out of AD and display it in a UI. Based on the server name selected by the user, I want give various options like system information, system update history, SQL Server Services on the system, Drive info, Databases and their physical paths and recovery model. This is just the brief outlook that I have.

I am a rookie in Powershell yet I have few Ideas I want to implement. Please help me…


In order to achieve my goal, first step is to present the list of ad computers in the UI. I am stuck here. Below is the code:
function Get-ComputerList
Import-Module ActiveDirectory
$array = @(get-ADComputer -Filter {Name -like ‘LAIDB’ -OR Name -like ‘HOLDB’ -OR Name -like ‘LAIW2KCL’ } -property * |Sort-Object Name `
| Format-Table Name, Description,IPV4Address, OperatingSystem, OperatingSystemServicePack,Created,LastLogonDate -Wrap -AutoSize |Out-Default)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = “Microsoft SQL Server Inventory Application”
$objForm.Size = New-Object System.Drawing.Size(1200,800)
$objForm.StartPosition = “CenterScreen”
$objForm.KeyPreview = $True

$dataGrid1 = New-Object System.Windows.Forms.DataGrid
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 1200
$System_Drawing_Size.Height = 650
$dataGrid1.Size = $System_Drawing_Size
$dataGrid1.DataBindings.DefaultDataSourceUpdateMode = 0
$dataGrid1.HeaderForeColor = [System.Drawing.Color]::FromArgb(255,0,0,0)
$dataGrid1.Name = “dataGrid1”
$dataGrid1.DataMember = “”
$dataGrid1.TabIndex = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 0
$dataGrid1.Location = $System_Drawing_Point

$items = Get-ComputerList
foreach($row in $items)
$newrow = [array]$row


[void] $objForm.showdialog()

Error Message:
[You cannot call a method on a null-valued expression.
At X:\Projects\PowerShellScripts\Work Scripts\ SQL Server Inventory Manager.ps1:38 char:21
+ $dataGrid1.Rows.Add <<<< ($newrow)
+ CategoryInfo : InvalidOperation: (Add:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Please help
by DonJ at 2013-04-06 06:25:28
Please refer to our “PowerShell and GUIs” forum. You’ll find better help on this topic there.