Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

Combining enumeration values

Closed Thread
 
Thread Tools Display Modes
Old 10-10-2007   #1 (permalink)
Robin Moffatt
Guest


 

Combining enumeration values

I'm calling a method that takes as a parameter ScriptOptions
enumeration (https://msdn2.microsoft.com/en-us/library/
microsoft.sqlserver.replication.scriptoptions.aspx)

I've worked out that I can do this:
$srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoptions]::Creation)

but what's the syntax to combine multiple values of the enumeration?

thanks, moff

Old 10-10-2007   #2 (permalink)
Kirk Munro
Guest


 

Re: Combining enumeration values

Hi Robin,

Use -bor between the enumeration values you want to combine. -bor is the
operator for bitwise or.

e.g.
$srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoptions]::Creation
-bor [Microsoft.SqlServer.Replication.scriptoptions]::SomeOtherValue)

-
Kirk Munro
Poshoholic
http://poshoholic.com

"Robin Moffatt" <robin.moffatt@xxxxxx> wrote in message
news:1192023274.325358.224760@xxxxxx
Quote:

> I'm calling a method that takes as a parameter ScriptOptions
> enumeration (https://msdn2.microsoft.com/en-us/library/
> microsoft.sqlserver.replication.scriptoptions.aspx)
>
> I've worked out that I can do this:
> $srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoptions]::Creation)
>
> but what's the syntax to combine multiple values of the enumeration?
>
> thanks, moff
>

Old 10-10-2007   #3 (permalink)
Shay Levi
Guest


 

Re: Combining enumeration values


This example lists all enum values and constants.
As for the syntax to combine values, check the FlagsAttribute option page
on MSDN
https://msdn2.microsoft.com/en-us/li...attribute.aspx


[void][reflection.assembly]::LoadWithPartialName("microsoft.sqlserver.rmo")
$e = [system.enum]::getvalues([Microsoft.SqlServer.Replication.scriptoptions])
0..($e.length-1) | select @{n="Value";e={[string][enum]:arse([Microsoft.SqlServer.Replication.scriptoptions],$_)}},
@{n="Constant";e={$_}} | format-table -autosize



Value
Constant
----
--------
None
0
Creation
1
Deletion
2
Creation, Deletion
3
IncludeArticles
4
Creation, IncludeArticles
5
Deletion, IncludeArticles
6
Creation, Deletion, IncludeArticles
7
IncludePublisherSideSubscriptions
8
Creation, IncludePublisherSideSubscriptions
9
Deletion, IncludePublisherSideSubscriptions
10
Creation, Deletion, IncludePublisherSideSubscriptions
11
IncludeArticles, IncludePublisherSideSubscriptions
12
Creation, IncludeArticles, IncludePublisherSideSubscriptions
13
Deletion, IncludeArticles, IncludePublisherSideSubscriptions
14
Creation, Deletion, IncludeArticles, IncludePublisherSideSubscriptions
15
IncludeSubscriberSideSubscriptions
16
Creation, IncludeSubscriberSideSubscriptions
17
Deletion, IncludeSubscriberSideSubscriptions
18
Creation, Deletion, IncludeSubscriberSideSubscriptions
19
IncludeArticles, IncludeSubscriberSideSubscriptions
20
Creation, IncludeArticles, IncludeSubscriberSideSubscriptions
21
Deletion, IncludeArticles, IncludeSubscriberSideSubscriptions
22
Creation, Deletion, IncludeArticles, IncludeSubscriberSideSubscriptions
23
IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
24
Creation, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
25
Deletion, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
26
Creation, Deletion, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
27
IncludeArticles, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
28
Creation, IncludeArticles, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
29
Deletion, IncludeArticles, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
30
Creation, Deletion, IncludeArticles, IncludePublisherSideSubscriptions, IncludeSubscriberSideSubscriptions
31
IncludePartialSubscriptions
32
Creation, IncludePartialSubscriptions
33



Shay
http://scriptolog.blogspot.com


Quote:

> I'm calling a method that takes as a parameter ScriptOptions
> enumeration (https://msdn2.microsoft.com/en-us/library/
> microsoft.sqlserver.replication.scriptoptions.aspx)
>
> I've worked out that I can do this:
> $srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scripto
> ptions]::Creation)
> but what's the syntax to combine multiple values of the enumeration?
>
> thanks, moff
>

Old 10-10-2007   #4 (permalink)
Roman Kuzmin
Guest


 

Re: Combining enumeration values

I a parameter is not ambiguous in this particular case you can use a string
of comma separated names of enum values:

$srv.ReplicationServer.Script('Creation,Whatever1,Whatever2')


--
Thanks,
Roman Kuzmin
PowerShellFar and FarNET: http://code.google.com/p/farnet/


"Robin Moffatt" <robin.moffatt@xxxxxx> wrote in message
news:1192023274.325358.224760@xxxxxx
Quote:

> I'm calling a method that takes as a parameter ScriptOptions
> enumeration (https://msdn2.microsoft.com/en-us/library/
> microsoft.sqlserver.replication.scriptoptions.aspx)
>
> I've worked out that I can do this:
> $srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoptions]::Creation)
>
> but what's the syntax to combine multiple values of the enumeration?
>
> thanks, moff
>

Old 10-10-2007   #5 (permalink)
Robin Moffatt
Guest


 

Re: Combining enumeration values


thanks to everyone for their answers :-)

Old 10-10-2007   #6 (permalink)
Oisin Grehan
Guest


 

Re: Combining enumeration values

On Oct 10, 10:13 am, "Kirk Munro" <so...@xxxxxx> wrote:
Quote:

> Hi Robin,
>
> Use -bor between the enumeration values you want to combine. -bor is the
> operator for bitwise or.
>
> e.g.
> $srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoption*s]::Creation
> -bor [Microsoft.SqlServer.Replication.scriptoptions]::SomeOtherValue)
>
> -
> Kirk Munro
> Poshoholichttp://poshoholic.com
>
You _can_ do it this way if you want to get early RSI ;-), but
alternatively you can use powershell's magic-casty bits (tm) to do the
hard work for you. Just pass the plain names, comma separated inside a
string, e.g. the above would be passed as:

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

Hope this helps,

- Oisin / x0n

Old 10-11-2007   #7 (permalink)
Robin Moffatt
Guest


 

Re: Combining enumeration values

On Oct 10, 5:39 pm, Oisin Grehan <ois...@xxxxxx> wrote:
Quote:

> You _can_ do it this way if you want to get early RSI ;-), but
> alternatively you can use powershell's magic-casty bits (tm) to do the
> hard work for you. Just pass the plain names, comma separated inside a
> string, e.g. the above would be passed as:
>
> $srv.ReplicationServer.Script("Creation,SomeOtherValue")
>
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.scriptoptions]::Creation
`
-bor
[Microsoft.SqlServer.Replication.scriptoptions]::IncludeAll `
-bxor
[Microsoft.SqlServer.Replication.scriptoptions]::IncludeReplicationJobs ))


cheers, moff.

Old 10-11-2007   #8 (permalink)
Oisin Grehan
Guest


 

Re: Combining enumeration values

On Oct 11, 5:23 am, Robin Moffatt <robin.moff...@xxxxxx> wrote:
Quote:

> On Oct 10, 5:39 pm, Oisin Grehan <ois...@xxxxxx> wrote:
>
Quote:

> > You _can_ do it this way if you want to get early RSI ;-), but
> > alternatively you can use powershell's magic-casty bits (tm) to do the
> > hard work for you. Just pass the plain names, comma separated inside a
> > string, e.g. the above would be passed as:
>
Quote:

> > $srv.ReplicationServer.Script("Creation,SomeOtherValue")
>
> 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 ))
>
> cheers, moff.
Sure, one way has you casting the operands, so you don't save as much
typing this time. e.g.

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

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

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

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

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

(because [$enum]"creation,includeall" won't work)

Hope this helps,

- Oisin / x0n

http://www.nivot.org/






Old 10-12-2007   #9 (permalink)
Robin Moffatt
Guest


 

Re: Combining enumeration values

[...]
Quote:

>
> PS > $options = $enum::all -bxor ("includeall, includereplicationjobs"
> -as $enum)
>
> (because [$enum]"creation,includeall" won't work)
>
> Hope this helps,
>
> - Oisin / x0n


Thanks

Old 10-23-2007   #10 (permalink)
Robin Moffatt
Guest


 

Re: Combining enumeration values

As a follow-on to this, how can I test an enumeration for a specific
value?
I'm doing this:
$dist_svr.ReplicationServer.DistributionPublishers[0].DistributionPublications[5].attributes
and attributes has the type
Microsoft.SqlServer.Replication.PublicationAttributes
So how can I test if an object has a specific bit set, eg.
[Microsoft.SqlServer.Replication.publicationattributes]::AllowAnonymous

TIA, moff


On Oct 10, 3:13 pm, "Kirk Munro" <so...@xxxxxx> wrote:
Quote:

> Hi Robin,
>
> Use -bor between theenumerationvalues you want to combine. -bor is the
> operator for bitwise or.
>
> e.g.
> $srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoptions]::Creation
> -bor [Microsoft.SqlServer.Replication.scriptoptions]::SomeOtherValue)
>
> -
> Kirk Munro
> Poshoholichttp://poshoholic.com
>
> "Robin Moffatt" <robin.moff...@xxxxxx> wrote in message
>
> news:1192023274.325358.224760@xxxxxx
>
Quote:

> > I'm calling a method that takes as a parameter ScriptOptions
> >enumeration(https://msdn2.microsoft.com/en-us/library/
> > microsoft.sqlserver.replication.scriptoptions.aspx)
>
Quote:

> > I've worked out that I can do this:
> > $srv.ReplicationServer.Script([Microsoft.SqlServer.Replication.scriptoptions]::Creation)
>
Quote:

> > but what's the syntax to combine multiple values of theenumeration?
>
Quote:

> > thanks, moff

Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
mirroringrole enumeration - script Frank PowerShell 3 11-19-2007 03:41 PM
How do you use .net enumeration values in powershell? Bob Landau PowerShell 3 09-20-2007 09:49 AM
How to Disable ''Write Combining''? Silentblade® Graphic cards 7 06-11-2007 11:22 AM
Disable Write Combining? Sniper82 Vista General 1 05-01-2007 10:26 PM
Networok Enumeration Majhoos Vista networking & sharing 0 02-13-2007 09:53 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50