Re-writing C/C++/C# Enums as PowerShell

I was going to call this post “Converting C/C++/C# Enums” but realised that might give a false sense of automation!  Here’s how I’d rewrite a C enum as PowerShell.  Is there a better way?  Thoughts?

Edit: I’ve gone off ‘-Option Constant’ – it makes testing and debugging excessively awkward…

Navigate enum from MSDN:

    typedef enum BrowserNavConstants {
navOpenInNewWindow = 0x1,
navNoHistory = 0x2,
navNoReadFromCache = 0x4,
navNoWriteToCache = 0x8,
navAllowAutosearch = 0x10,
navBrowserBar = 0x20,
navHyperlink = 0x40,
navEnforceRestricted = 0x80,
navNewWindowsManaged = 0x0100,
navUntrustedForDownload = 0x0200,
navTrustedForActiveX = 0x0400,
navOpenInNewTab = 0x0800,
navOpenInBackgroundTab = 0x1000,
navKeepWordWheelText = 0x2000,
navVirtualTab = 0x4000,
navBlockRedirectsXDomain = 0x8000,
navOpenNewForegroundTab = 0x10000
} BrowserNavConstants;

    # Define enum values as PS Constants
Set-Variable -Option Constant    CONST_navOpenInNewWindow        0x00001
Set-Variable -Option Constant    CONST_navNoHistory                0x00002
Set-Variable -Option Constant    CONST_navNoReadFromCache        0x00004
Set-Variable -Option Constant    CONST_navNoWriteToCache        0x00008
Set-Variable -Option Constant    CONST_navAllowAutosearch        0x00010
Set-Variable -Option Constant    CONST_navBrowserBar            0x00020
Set-Variable -Option Constant    CONST_navHyperlink                0x00040
Set-Variable -Option Constant    CONST_navEnforceRestricted        0x00080
Set-Variable -Option Constant    CONST_navNewWindowsManaged        0x00100
Set-Variable -Option Constant    CONST_navUntrustedForDownload    0x00200
Set-Variable -Option Constant    CONST_navTrustedForActiveX        0x00400
Set-Variable -Option Constant    CONST_navOpenInNewTab            0x00800
Set-Variable -Option Constant    CONST_navOpenInBackgroundTab    0x01000
Set-Variable -Option Constant    CONST_navKeepWordWheelText        0x02000
Set-Variable -Option Constant    CONST_navVirtualTab            0x04000
Set-Variable -Option Constant    CONST_navBlockRedirectsXDomain    0x08000
Set-Variable -Option Constant    CONST_navOpenNewForegroundTab    0x10000



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s