Enum like switch parameter in PowerShell

Viewed 45456

I am using switch parameters in my PowerShell script in this fashion.

param(
    [switch] $Word,
    [switch] $Excel,
    [switch] $powerpoint,
    [switch] $v2007,
    [switch] $v2010,
    [switch] $x86,
    [switch] $x64,
)

I am trying to figure out any neat way to have it more enum style. As anyone might guess, I would want the user to choose between word, excel and powerpoint. And between x2007 and v2010.

Is there a neat way to get input params enum style?

I am new to PowerShell. So if this sounds like that I don't know something obvious, then please point me to some link where I can read about it.

4 Answers

Since PowerShell 5 you can actually use/create an Enum natively.

enum OS {
    Windows
    Linux
    iOS
}

This is then also visible as its type.

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     OS                                       System.Enum

Maybe a useful link by 4sysops.

Related