![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
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.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| 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 |
| | #2 (permalink) | ||||||||||||
| 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
| ||||||||||||
| | #3 (permalink) | ||||||||||||
| 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
| ||||||||||||
| | #4 (permalink) | ||||||||||||
| 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
| ||||||||||||
| | #6 (permalink) | ||||||||||||
| Guest | Re: Combining enumeration values On Oct 10, 10:13 am, "Kirk Munro" <so...@xxxxxx> wrote:
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 | ||||||||||||
| | #7 (permalink) | ||||||||||||
| Guest | Re: Combining enumeration values On Oct 10, 5:39 pm, Oisin Grehan <ois...@xxxxxx> wrote:
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. | ||||||||||||
| | #8 (permalink) | ||||||||||||||||||||||||||||||||||||
| Guest | Re: Combining enumeration values On Oct 11, 5:23 am, Robin Moffatt <robin.moff...@xxxxxx> wrote:
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/ | ||||||||||||||||||||||||||||||||||||
| | #10 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |
| |
![]() |
| 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 |