Chapter 25. Creating a GUI tool, part 3: the output

 

In the previous two chapters, we showed you how to create a GUI and add functionality to it. In this chapter, we’ll take that functionality and use it to create some output for the application’s user. We’ll focus on two techniques: the easy, built-in way of generically displaying output and the harder, more customized way of building your own output form.

25.1. Using Out-GridView

We’ll start by using the Out-GridView cmdlet, which will be available on any computer that has the PowerShell ISE installed. We’ll make one minor change to our application’s OK button handler; the complete handler is listed here:

$OKButton_Click={
    if ($EventLogName.Visible) {
        # retrieve event log
        if ($EventLogName.SelectedIndex -gt -1) {
            $entries = Get-EventLog -Computer $ComputerName.Text `
                                    -Log $EventLogName.SelectedItem
            $entries | Out-GridView
        }
    } else {
        # populate event log list
        $logs = Get-EventLog -ComputerName $ComputerName.Text `
                             -List |
                Select-Object -ExpandProperty Log
        Load-ComboBox -ComboBox $EventLogName `
                      -Items $logs
        $EventLogName.Visible = $true
        $labelSelectEventLog.Visible = $true
    }
}

25.2. Creating a form for output

25.3. Populating and showing the output

25.4. Lab