# Thursday, October 11, 2007

A question came up on the PowerShell newsgroup concerning how to use enums, particularly the shortcut form whereby posh will coerce strings. Roman Kuzmin of PowerShell/FarNet fame offered up a quick answer on how to provide multiple values to be "or'd" together for [flags] decorated enums:

$srv.ReplicationServer.Script("Creation,SomeOtherValue")

To which the original poster (moff) replied:

Out of interest, can this syntax be used for xor'ing values together too? 
At the moment my statement looks like this: 


$pub_svr.ReplicationServer.Script(([Microsoft.SqlServer.Replication.scripto­­ptions]::Creation `
    -bor [Microsoft.SqlServer.Replication.scriptoptions]::IncludeAll ` 
    -bxor [Microsoft.SqlServer.Replication.scriptoptions]::IncludeReplicationJobs ))

To which I explained that sure, one way has you casting the operands (using system.attributetargets as the enum example):

$targets = ([attributetargets]"all" -bxor [attributetargets]"event,field")

And if the type name is long, another handy trick is to assign the enum type to a variable, e.g.

$enum = [Microsoft.SqlServer.Replication.ScriptO­ptions] 
$options = ($enum::creation -bor $enum::IncludeAll) -bxor $enum::includereplicationjobs

...and finally, if you want to cast multiple flags using a variable shortcut, use the -as operator:

$options = $enum::all -bxor ("includeall,includereplicationjobs" -as $enum)

because [$enum]"creation,includeall" (or other guessed-at variants) won't work.

posted on Thursday, October 11, 2007 10:30:27 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
Related posts:
PowerShell v2.0 – Differences Between CTP3/Win7Beta and Win7RC
Pscx 1.2 Beta Released
PowerShell 2.0 CTP3: Modules, in Practice - Closures
PowerShell 2.0 CTP3: Modules, in Practice – .NET Interfaces
PowerShell 2.0 CTP3: Modules, in Practice.
Visual Studio 2008 Extensions for WSS 3.0 v1.3 March CTP

Referred by:
powershell how to use net enumerations (www.google.com) [Referral]
powershell (search.live.com) [Referral]
enums in powershell (www.google.com) [Referral]
http://blogs.msdn.com/powershell/archive/2007/10/29/dynamic-... [Referral]
enum types sql server (www.google.it) [Referral]
powershell enumeration (www.google.com) [Referral]
powershell enum type (www.google.nl) [Referral]
enumerated powershell (www.google.at) [Referral]
powershell enum com (www.google.com) [Referral]
enum + powershell (www.google.fr) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enumerations (www.google.se) [Referral]
type accelerator enumerate powershell (www.google.co.uk) [Referral]
Using enums in PowerShell (www.google.se) [Referral]
feed list into powershell (www.google.com) [Referral]
PowerShell using Enums (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enum syntax (www.google.com) [Referral]
powershell enumerated (www.google.com.sg) [Referral]
enumeration members in powershell (www.google.com) [Referral]
using enums in powershell (search.live.com) [Referral]
enums in powershell (www.google.com) [Referral]
powershell using .Net enum (www.google.cz) [Referral]
using enums in powershell (www.google.com) [Referral]
powershell enumerated types (www.google.co.uk) [Referral]
powershell enum types (www.google.com) [Referral]
enum powershell (www.google.co.uk) [Referral]
powershell enumeration (search.live.com) [Referral]
powershell enum type (www.google.ca) [Referral]
powershell enum type (www.google.com) [Referral]
powershell com enumeration (www.google.ca) [Referral]
powershell "[enum]" (www.google.co.uk) [Referral]
powershell enum type (www.google.com) [Referral]
powershell enum flags (www.google.com) [Referral]
powershell 2.0 enum (www.google.com) [Referral]
powershell enums (www.google.com) [Referral]
powershell using enumerations (www.google.com) [Referral]
http://clusty.com/search?input-form=clusty-simple&v%3Asource... [Referral]
enumerate powershell (www.google.nl) [Referral]
enums in powershell (www.google.lt) [Referral]
http://store.liftmaster-remote.com/ [Referral]
Powershell use multiple variables in where (www.google.com) [Referral]
Enum in powershell (www.google.ru) [Referral]
PowerShell enum (www.google.es) [Referral]
powershell enums (www.google.com) [Referral]
powershell list enum (www.google.com) [Referral]
using enum in powershell (www.google.com) [Referral]
powershell .net enums (www.google.com) [Referral]
powershell enumerated (www.google.co.nz) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enums (www.google.com) [Referral]
http://store.liftmaster-remote.com/liftmaster371lm.html [Referral]
http://www.liftmaster-371lm.com/ [Referral]
enums in powershell cmdlets (www.google.com) [Referral]
powershell enumerated (www.google.cz) [Referral]
powershell enum member (www.google.co.uk) [Referral]
powershell xor enumerations (www.google.com) [Referral]
powershell enumerations (www.google.co.uk) [Referral]
powershell enum operators (www.google.com) [Referral]
powershell assign enum to variable (www.google.com) [Referral]
powershell enumeration (www.google.be) [Referral]
enumerating using commas (www.google.ca) [Referral]
powershell enumeration list (www.google.com) [Referral]
powershell flags enum (www.google.com) [Referral]
powershell using enums (www.google.co.nz) [Referral]
powershell .net enum (www.google.de) [Referral]
enumeration in powershell (www.google.com) [Referral]
http://store.liftmaster-remotes.com/ [Referral]
types of operands using in power pc (search.msn.com) [Referral]
ReplicationServer.Script powershell (www.google.co.nz) [Referral]
using enumerated types in Powershell (www.google.com) [Referral]
enums in PowerShell (www.google.ru) [Referral]
powershell enumerations (www.google.nl) [Referral]
powershell enums (www.google.pl) [Referral]
powershell use .Net (www.google.ru) [Referral]
powershell using type (www.google.com) [Referral]
powershell use a .net enum (www.google.co.uk) [Referral]
powershell enums (www.google.com) [Referral]
enumeration in powershell (www.google.com) [Referral]
powershell .net enumeration (www.google.com) [Referral]
powershell list enum values (www.google.ch) [Referral]
enumeration powershell (www.google.com) [Referral]
-MemberType enumeration powershell (www.google.ca) [Referral]
powershell enumeration (www.google.com) [Referral]
powershell enum (www.google.com) [Referral]
powershell enum (www.google.com) [Referral]
enumeration powershell (www.google.es) [Referral]
powershell enum (www.google.co.uk) [Referral]
powershell enumerate (www.google.pl) [Referral]
powershell enumeration types (www.google.com) [Referral]
enum in powershell (www.google.com) [Referral]
powershell enumerations (www.google.co.uk) [Referral]
powershell enumerate (www.google.co.uk) [Referral]
Enumeration powershell (www.google.com) [Referral]
powershell enum (www.google.com) [Referral]
flag enum powershell (www.google.com) [Referral]
powershell enum (www.google.sk) [Referral]
powershell enumerated type (www.google.com.au) [Referral]
flag enum powershell (www.google.fr) [Referral]
powershell enums (www.google.com) [Referral]
powershell using enums (www.google.com) [Referral]
.net enumerated types in powershell (www.google.com) [Referral]
.net enumerated powershell (www.google.com) [Referral]
powershell Microsoft.SqlServer.Replication (www.google.com) [Referral]
+powershell +enumerate (www.google.com) [Referral]
using enumerations in powershell (www.kumo.com) [Referral]
powershell + enum members (www.google.com) [Referral]
types of operands using in power pc+pdf (www.google.co.in) [Referral]
PowerShell Enumration (www.google.co.jp) [Referral]
PowerShell enumerations (www.kumo.com) [Referral]
powershell enum (www.google.com) [Referral]
enumeration powershell (www.google.de) [Referral]
PowerShell enum (www.google.co.jp) [Referral]
$pub_svr.ReplicationServer.Script(( (www.google.co.uk) [Referral]
how to work with enumerated .net types in powershell (www.google.com) [Referral]
powershell enumeration values (www.kumo.com) [Referral]
powershell .net types (www.kumo.com) [Referral]
powershell enum (www.google.com) [Referral]
powershell read xml enumeration (www.google.co.uk) [Referral]
enum creation in asp.net (www.google.co.in) [Referral]
enum in powershell (www.google.com) [Referral]
powershell enum (www.google.de) [Referral]
powershell get .net enumerations (www.google.com) [Referral]
IncludeReplicationJobs (search.msn.com) [Referral]
powershell enum member (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
use enumeration in powershell (www.google.co.uk) [Referral]
.net enumeration in powershell (www.google.com) [Referral]
powershell enumerated types (www.google.com) [Referral]
.net enumeration in powershell (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
set enumeration type in powershell (www.google.co.uk) [Referral]
xor enumeration flags sql server data type (www.google.com) [Referral]
"sqlserver" enum (www.google.es) [Referral]
powershell flags (www.google.com) [Referral]
using flag enumeration asp.net sql (www.google.com) [Referral]
Using enum type in powershell script (www.google.co.uk) [Referral]
powershell enum (www.google.dk) [Referral]
+powershell +enums (www.google.nl) [Referral]
ReplicationServer.Script (www.google.co.uk) [Referral]
powershell ReplicationServer.Script (www.google.co.uk) [Referral]
powershell enums (www.google.se) [Referral]
codeplex enum flags (www.google.cz) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell finding enums (www.google.com) [Referral]
powershell flags enum (www.google.nl) [Referral]
powershell enum (www.google.nl) [Referral]
powershell cast enum (www.google.nl) [Referral]
powershell enums (www.google.co.nz) [Referral]
powershell enum full (www.google.com) [Referral]
powershell + enumerate + values (www.google.com.au) [Referral]
enums in powershell (www.google.com) [Referral]
enum all framework powershell (www.google.de) [Referral]
enumeration in powershell (www.google.com) [Referral]
powershell enumerate (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enum type (www.google.com.au) [Referral]
using Enumerated Types with Visual Studio 2008 (www.google.co.za) [Referral]
powershell enumerating value (www.google.be) [Referral]
powershell enum variable (www.google.com) [Referral]
working with enums powershell (www.google.com) [Referral]
enum powershell (search.live.com) [Referral]
enum powershell variables (www.google.com) [Referral]
powershell Microsoft.SqlServer.Replication.ReplicationServer (www.google.co.uk) [Referral]
powershell enum variable (www.google.com) [Referral]
powershell enums (www.google.com) [Referral]
powershell script power pc (www.google.com.mx) [Referral]
powershell compare enum (www.google.com) [Referral]
enumerated type + powershell (www.google.com) [Referral]
powershell enum (www.google.ch) [Referral]
"powershell -bxor value" (www.google.ca) [Referral]
Powershell cmdlets enumeration (www.google.com) [Referral]
powershell flags (www.google.com) [Referral]
powershell get enumeration values (www.google.de) [Referral]
powershell enumerate variables (www.google.de) [Referral]
powershell use Enums (www.google.com) [Referral]
powershell enumeration (www.google.com) [Referral]
Microsoft.VisualStudio.Shell enum types (www.google.com) [Referral]
powershell .net enumeration (www.google.be) [Referral]
SharePoint powershell enum (www.kumo.com) [Referral]
flags enum sql server datatype (www.google.com) [Referral]
powershell enumerate (www.google.com) [Referral]
powershell enum (www.google.ru) [Referral]
flags enum casting (www.google.co.il) [Referral]
sql server enum type (www.google.com) [Referral]
powershell enumerations (www.google.nl) [Referral]
powershell Enumerations (search.live.com) [Referral]
enumerated types in powershell (www.google.co.nz) [Referral]
powershell pass enumerated types (www.google.com) [Referral]
powershell enumerate (www.google.com) [Referral]
using enums in powershell (www.google.com) [Referral]
sharepoint stsadm enum powershell scripts (www.google.com) [Referral]
enum powershell (www.google.com) [Referral]
powershell enum type (www.google.com.sg) [Referral]
powershell enums (www.google.com) [Referral]
powershell ctp3 enum (www.google.com) [Referral]
powershell enumerate options (www.google.com) [Referral]
how to use flagged enum in powershell script (www.google.ru) [Referral]
"enums in powershell" (www.google.com) [Referral]
"enums in powershell" (www.google.com) [Referral]
.net enumeration powershell (www.google.co.uk) [Referral]
powershell list values in enum (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
poweshell enumerations (www.google.com) [Referral]
PowerShell enums (www.google.com) [Referral]
using Enumeration powershell (www.google.co.uk) [Referral]
powershell enum (www.google.com) [Referral]
PowerShell enumerations (www.google.com) [Referral]
passing enumeration powershell (www.google.com) [Referral]
passing multiple enumeration value powershell (www.google.com) [Referral]
enumeration powershell (www.google.com) [Referral]
pass multiple enum powershell script (www.google.com) [Referral]
powershell Enumerate (www.google.com) [Referral]
enum flags sql (www.google.ru) [Referral]
powershell enum (www.bing.com) [Referral]
SharePoint enum powershell (www.bing.com) [Referral]
powershell using enums (www.google.pl) [Referral]
enumeration powershell (www.google.com) [Referral]
PowerShell enumeration SharePoint (www.bing.com) [Referral]
powershell enums (www.bing.com) [Referral]
using enumerations in powershell (www.google.ca) [Referral]
"Enum Types" powershell (www.google.com.au) [Referral]
"Enum Types" powershell using + (www.google.com.au) [Referral]
.net enumeration powershell (www.google.com) [Referral]
powershell enumerations (www.bing.com) [Referral]
.NET enums powershell (www.bing.com) [Referral]
powershell type enumerate (www.google.cn) [Referral]
sharepoint enum types (www.google.es) [Referral]
powershell xor (www.google.co.uk) [Referral]
powershell list enums (www.google.com) [Referral]
powerhshell .net enumerations (www.google.com) [Referral]
powershell enumeration .net (www.google.com) [Referral]
use enum powershell (www.google.com.hk) [Referral]
powershell list enum (www.google.com) [Referral]
enumeration powershell (www.google.com) [Referral]
powershell enumerations (www.google.com) [Referral]
enumerations in powershell (www.google.be) [Referral]
.net enum xor (www.google.nl) [Referral]
powershell EnumMembers (www.google.com) [Referral]
enum powershell script (www.google.com) [Referral]
powershell script enum (www.google.co.uk) [Referral]
using .NET enum values in powershell (www.google.com) [Referral]
enum powershell (www.google.co.uk) [Referral]
PowerShell enums (www.google.com) [Referral]
powershell xml enumerate (www.google.com) [Referral]
powershell using enumerations (www.bing.com) [Referral]
powershell function pass enum (www.google.com) [Referral]
enum sql server (www.bing.com) [Referral]
powershell enum compare (www.google.com) [Referral]
powershell flags (www.google.com) [Referral]
powershell .net enum problem (www.google.com) [Referral]
powershell list value of all members (www.bing.com) [Referral]
powershell enums (www.google.pl) [Referral]
powershell flag enumeration (www.google.com) [Referral]
.net enum type sql 2008 (www.bing.com) [Referral]
enumerate enums (search.yahoo.com) [Referral]
powershell enumerate variables (www.google.fr) [Referral]
powershell enum (www.bing.com) [Referral]
powershell flags (www.google.com) [Referral]
powershell enumerate xml (www.bing.com) [Referral]
Enumeration ScriptOptions (www.google.com) [Referral]
powershell .net enums? (www.google.com) [Referral]
powershell use enumerations (www.google.com) [Referral]
compare to enum in powershell (www.google.fi) [Referral]
enum powershell (www.bing.com) [Referral]
powershell enumerate (www.google.com) [Referral]
flag enum xor (www.google.com) [Referral]
powershell data types (www.bing.com) [Referral]
powershell enumerations (www.bing.com) [Referral]
flag enums in powershell (www.bing.com) [Referral]
powershell how to list enumeration (www.bing.com) [Referral]
powershell enumeration (www.google.com) [Referral]
powershell enum example (www.google.com) [Referral]
powershell pass enum (www.google.de) [Referral]
"powershell" stsadm enum site collection (www.google.at) [Referral]
powershell enumerate variable (www.google.com) [Referral]
+powershell +enumeration values (www.google.com) [Referral]
Comments are closed.