Validate Set of Inputs

by Aug 18, 2010

If you need to limit a function parameter to only a set of allowed choices, you should use the next example:

function Get24hEventLogEntries {


Get-EventLog -LogName $LogName -EntryType $EntryType -After ((Get-Date).AddDays(1))


You can use Get-24hEventLogEntries to retrieve events written in the past 24 hours. The user can choose to see the 'system' or the 'application' log. EntryType is limited to 'Error,' 'Warning,' or 'Information.'

Twitter This Tip! ReTweet this Tip!