O'Reilly logo

Learn PowerShell Toolmaking in a Month of Lunches by Don Jones and Jeffrey Hicks

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

24.4. Example: list boxes

This is the tricky part of our script. Fortunately, PowerShell Studio gives us a helper function that makes it easier to populate our drop-down list. To use that, we’ll need to retrieve a list of event log names as plain strings, which we’ll store in the variable $logs:

$logs = Get-EventLog -ComputerName $ComputerName.Text `
                     -List |
        Select-Object -ExpandProperty Log

Note that the –ExpandProperty parameter of Select-Object is crucial here. Normally, Get-EventLog returns a collection of objects, and the event log name is in the Log property of those objects. We need to extract that information so that it’s a plain String, because plain Strings are what we need to put into the drop-down list box.

We then call the Load-ComboBox ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required