Validate Set of Inputs

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

function Get-24hEventLogEntries {
param(
[String]
[ValidateSet('System','Application')]
$LogName='System',

[String]
[ValidateSet('Error','Warning','Information')]
$EntryType='Error'
)

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!


Posted Aug 18 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.