Create UI using PowerShell - DataGrid
Posted: Sat Apr 06, 2013 9:50 am
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..
Problem:
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:
[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
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..
Problem:
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:
PowerShell Code
Double-click the code block to select all.function Get-ComputerList { Import-Module ActiveDirectory $array = @(get-ADComputer -Filter {Name -like 'LAI*DB*' -OR Name -like 'HOL*DB*' -OR Name -like 'LAIW2K*CL*' } -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 $objForm.Add_Shown({$objForm.Activate()}) $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 #$dataGrid1.Rows.Add($items) foreach($row in $items) { $newrow = [array]$row $newrow $dataGrid1.Rows.Add($newrow) } $objForm.Controls.Add($dataGrid1) [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