Cash Talks - BS Walks RSS 2.0
# Saturday, 13 October 2007

This morning I did a little exercise.  Because PowerShell does not have C#'s Using Statement, Class references have to be fully qualified.  This includes Enumeration Values.  IMHO, this can make calls to managed methods a bit wordy.

In order to manage this, I have at times initialized a hash table with enumeration values.  For example, to initialize the values of System.Security.Cryptography.CipherMode I would create the following.


$CipherMode = @{}
$CipherMode.OFB = [System.Security.Cryptography.CipherMode]::OFB
$CipherMode.CFB = [System.Security.Cryptography.CipherMode]::CFB
$CipherMode.CBC = [System.Security.Cryptography.CipherMode]::CBC
$CipherMode.ECB = [System.Security.Cryptography.CipherMode]::ECB
$CipherMode.CTS = [System.Security.Cryptography.CipherMode]::CTS



This allows use of $CipherMode.CBC instead of [System.Security.Cryptography.CipherMode]::CBC.  While I found this handy at times, it is arduous to initialize.  And this one only has 5 values.

I developed a couple of functions that take the drudgery out of it.  The usage is:


$CipherMode = Get-EnumValues "System.Security.Cryptography.CipherMode"


This as easily handles enumeration of 2 or 200.  Beauty!

I also made a helper function that will simply show me the enumeration names:

Get-EnumNames "System.Security.Cryptography.CipherMode"

This will return:

CBC
ECB
OFB
CFB
CTS


The Source Code is as follows:


function Get-ValidEnumClass ([string] $ClassName = ${Throw "Class Name is required"})
{
  $type = [System.Type]::GetType($ClassName)
  if ($type -eq $null)
  {
    throw "Invalid Class Name or Assembly not loaded for [$ClassName]"
  }
  if (!$type.IsEnum)
  {
    throw "Invalid Enum Class [$ClassName]"
  }
  $type
}

function Get-EnumNames ($EnumClass = ${Throw "Valid Enum Class Name or Type is required"})
{
  if ($EnumClass -is [string])
  {
    $EnumClass = Get-ValidEnumClass $EnumClass
  }
  [
System.Enum]::GetNames($EnumClass)
}

function Get-EnumValues ([string] $EnumClassName = ${Throw "Valid Enum Class Name is required"})
{
  $type = Get-ValidEnumClass $EnumClassName
  $enumNames = Get-EnumNames $type
  $values = @{}
 
  foreach
($name in $enumNames)
  {
    $values[$name] = $type::$name.GetHashCode()
  }
  $values
}

Saturday, 13 October 2007 22:36:50 (GMT Daylight Time, UTC+01:00)  #    Comments [1178] -
Powershell
Tracked by:
"http://morningside.edu/mics/_notes/pages/clomid/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/hoodia/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/coumadin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/nexium/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/claritin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/accutane/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/zoloft/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/synthroid/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/claritin/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/celexa/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/soma/index.html" (http://morningside.e... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://morningside.edu/mics/_notes/pages/lipitor/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/lipitor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/clomid/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/lexapro/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/paxil/index.html" (http://blastpr.com/wiki/js/... [Pingback]
"http://blastpr.com/wiki/js/pages/prozac/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/wellbutrin/index.html" (http://blastpr.com/wik... [Pingback]
"http://morningside.edu/mics/_notes/pages/wellbutrin/index.html" (http://morning... [Pingback]
"http://blastpr.com/wiki/js/pages/synthroid/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/rainbow-brite/index.html" (http://blastpr.com/... [Pingback]
"http://morningside.edu/mics/_notes/pages/prozac/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/effexor/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/cymbalta/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/paxil/index.html" (http://morningside.... [Pingback]
"http://morningside.edu/mics/_notes/pages/viagra/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/ultram/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/melatonin/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/lexapro/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/prilosec/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/celexa/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/cialis/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/tramadol/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/effexor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/84238305/index.html" (http://blog.n... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/52060005/index.html" ... [Pingback]
"http://thebix.com/includes/compat/docs/44694113/index.html" (http://thebix.com/... [Pingback]
"http://martinrozon.com/images/photos/docs/56637999/index.html" (http://martinro... [Pingback]
"http://thejohnslater.com/pix/img/docs/56008043/index.html" (http://thejohnslate... [Pingback]
"http://jivest2006.com/docs/76826750/index.html" (http://jivest2006.com/docs/768... [Pingback]
"http://pspdesktops.com/fileupload/store/docs/18769945/index.html" (http://pspde... [Pingback]
"http://temerav.com/images/menu/05559064/index.html" (http://temerav.com/images/... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/60974094/index.h... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/73811526/index.html" (... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/04726190/index.html" (http://vlada... [Pingback]
"http://swellhead.netswellhead.net/docs/84545083/index.html" (http://swellhead.n... [Pingback]
"http://legambitdufou.org/Library/docs/64933533/index.html" (http://legambitdufo... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/87090382/index.h... [Pingback]
"http://legambitdufou.org/Library/docs/38152786/index.html" (http://legambitdufo... [Pingback]
"http://discussgod.com/cpstyles/docs/43932298/index.html" (http://discussgod.com... [Pingback]
"http://thebix.com/includes/compat/docs/15132509/index.html" (http://thebix.com/... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/68291686/index.h... [Pingback]
"http://seo4u.at/images/docs/76783685/index.html" (http://seo4u.at/images/docs/7... [Pingback]
"http://legambitdufou.org/Library/docs/15090396/index.html" (http://legambitdufo... [Pingback]
"http://martinrozon.com/images/photos/docs/43274485/index.html" (http://martinro... [Pingback]
"http://thebix.com/includes/compat/docs/51589391/index.html" (http://thebix.com/... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/37348396/index.html" ... [Pingback]
"http://plantmol.com/docs/99021843/index.html" (http://plantmol.com/docs/9902184... [Pingback]
"http://martinrozon.com/images/photos/docs/54373182/index.html" (http://martinro... [Pingback]
"http://coolioness.com/attachments/docs/75395149/index.html" (http://coolioness.... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/16705258/index.html" (... [Pingback]
"http://lecouac.org/ecrire/lang/docs/25282359/index.html" (http://lecouac.org/ec... [Pingback]
"http://add2rss.com/img/design/docs/73396176/index.html" (http://add2rss.com/img... [Pingback]
"http://hrvatska.biz/wp-includes/js/docs/80692203/index.html" (http://hrvatska.b... [Pingback]
"http://coolioness.com/attachments/docs/03698289/index.html" (http://coolioness.... [Pingback]
"http://allfreefilms.com/wp-includes/js/27702077/index.html" (http://allfreefilm... [Pingback]
"http://add2rss.com/img/design/docs/90861918/index.html" (http://add2rss.com/img... [Pingback]
"http://pddownloads.com/docs/15972574/index.html" (http://pddownloads.com/docs/1... [Pingback]
"http://coolioness.com/attachments/docs/76375390/index.html" (http://coolioness.... [Pingback]
"http://seo4u.at/images/docs/68897595/index.html" (http://seo4u.at/images/docs/6... [Pingback]
"http://thebix.com/includes/compat/docs/10152421/index.html" (http://thebix.com/... [Pingback]
"http://entartistes.ca/images/images/docs/28212733/index.html" (http://entartist... [Pingback]
"http://slaterjohn.com/downloads/2col/28436634/index.html" (http://slaterjohn.co... [Pingback]
"http://coolioness.com/attachments/docs/83777724/index.html" (http://coolioness.... [Pingback]
"http://allfreefilms.com/wp-includes/js/46226552/index.html" (http://allfreefilm... [Pingback]
"http://legambitdufou.org/Library/docs/28049195/index.html" (http://legambitdufo... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/36483653/index.html" ... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/06712704/index.h... [Pingback]
"http://slaterjohn.com/downloads/2col/51579700/index.html" (http://slaterjohn.co... [Pingback]
"http://easytravelcanada.info/js/pages/12/wellbutrin/" (http://easytravelcanada.... [Pingback]
"http://sevainc.com/bad_denise/img/1/accutane/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://ina-tv.sk/img/cialis/" (http://ina-tv.sk/img/cialis/) [Pingback]
"http://sevainc.com/bad_denise/img/7/melatonin/" (http://sevainc.com/bad_denise/... [Pingback]
"http://abaffydesign.com/la/img/cialis/" (http://abaffydesign.com/la/img/cialis/... [Pingback]
"http://inatelevizia.sk/ad/img/viagra/" (http://inatelevizia.sk/ad/img/viagra/) [Pingback]
"http://easytravelcanada.info/js/pages/11/ultram/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/2/celexa/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/12/zoloft/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://sevainc.com/bad_denise/img/10/soma/" (http://sevainc.com/bad_denise/img/... [Pingback]
"http://birds.sk/img/viagra/" (http://birds.sk/img/viagra/) [Pingback]
"http://easytravelcanada.info/js/pages/3/clomid/" (http://easytravelcanada.info/... [Pingback]
"http://easytravelcanada.info/js/pages/7/nexium/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/1/celebrex/" (http://sevainc.com/bad_denise/i... [Pingback]
"abaffy.org/la/img/viagra/" (abaffy.org/la/img/viagra/) [Pingback]
"http://easytravelcanada.info/js/pages/10/synthroid/" (http://easytravelcanada.i... [Pingback]
"http://sevainc.com/bad_denise/img/5/effexor/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easytravelcanada.info/js/pages/4/cymbalta/" (http://easytravelcanada.inf... [Pingback]
"http://sevainc.com/bad_denise/img/8/paxil/" (http://sevainc.com/bad_denise/img/... [Pingback]
"http://sevainc.com/bad_denise/img/9/prozac/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://easymexico.info/images/img/viagra/" (http://easymexico.info/images/img/v... [Pingback]
"http://easytravelcanada.info/js/pages/1/celebrex/" (http://easytravelcanada.inf... [Pingback]
"http://easytravelcanada.info/js/pages/4/coumadin/" (http://easytravelcanada.inf... [Pingback]
"http://sevainc.com/bad_denise/img/4/cymbalta/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://inatelevizia.sk/ad/img/cialis/" (http://inatelevizia.sk/ad/img/cialis/) [Pingback]
"http://sevainc.com/bad_denise/img/8/prilosec/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://birds.sk/img/cialis/" (http://birds.sk/img/cialis/) [Pingback]
"http://easytravelcanada.info/js/pages/9/rainbow-brite/" (http://easytravelcanad... [Pingback]
"http://easytravelcanada.info/js/pages/1/accutane/" (http://easytravelcanada.inf... [Pingback]
"http://easytravelcanada.info/js/pages/2/cialis/" (http://easytravelcanada.info/... [Pingback]
"abaffy.org/la/img/cialis/" (abaffy.org/la/img/cialis/) [Pingback]
"http://easytravelcanada.info/js/pages/10/soma/" (http://easytravelcanada.info/j... [Pingback]
"http://easytravelcanada.info/js/pages/6/lexapro/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/5/effexor/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/12/zoloft/" (http://easytravelcanada.info... [Pingback]
"http://easymexico.info/images/img/cialis/" (http://easymexico.info/images/img/c... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/the-internet-is-for-porn.... [Pingback]
"http://odin.net/images/pages/35694472/xxx-message-boards.html" (http://odin.net... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/barbue-girl.html" (http:/... [Pingback]
"http://odin.net/images/pages/35694472/hottest-movie-sex-scenes.html" (http://od... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/debra-wilson-nude-pics.htm... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/erotic-pictures-of-oral-s... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/adult-free-gay-porn.html" ... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/gay-baseball-player.html" ... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/ghanaian-girls.html" (htt... [Pingback]
"http://odin.net/images/pages/35694472/mature-and-teen-sex-clips.html" (http://o... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/view-free-sex-scenes.html"... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/what-is-the-mature-ripene... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/teenage-girl-nude.html" (... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/animal-sex-bondage.html" (... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/kid-sex.html" (http://cide... [Pingback]
"http://odin.net/images/pages/52807681/free-unlimited-ipod-porn.html" (http://od... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/britney-spears-nude-crotc... [Pingback]
"http://odin.net/images/pages/52807681/britney-sex-tape-just-a-rumor.html" (http... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/chyna-porn-movie.html" (ht... [Pingback]
"http://odin.net/images/pages/52807681/sexy-thai.html" (http://odin.net/images/p... [Pingback]
"http://odin.net/images/pages/52807681/black-teen-dare-dance.html" (http://odin.... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-lactation.html" (ht... [Pingback]
"http://odin.net/images/pages/52807681/costume-drama-porn.html" (http://odin.net... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/little-match-girl-story.h... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/young-girls-sex-video.html... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/gay-porn-websites.html" (... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/vip-adult-clubs.html" (htt... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/sex-gadis-melayu.html" (ht... [Pingback]
"http://odin.net/images/pages/35694472/sexy-female-escorts-in-delhi.html" (http:... [Pingback]
"http://odin.net/images/pages/35694472/babe-like-swim-video.html" (http://odin.n... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/nude-celeb-thumbs.html" (... [Pingback]
"http://odin.net/images/pages/35694472/free-adult-sex-classifieds-china.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/camping-naturisten-free-p... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/taylor-hayes-free-pics.ht... [Pingback]
"http://odin.net/images/pages/35694472/danni-hunt-in-nude.html" (http://odin.net... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/asian-woman-for-anal-sex.h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/granny-movie-thumbs.html"... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/cheeta-girls.html" (http:/... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/anime-preteen-sex.html" (... [Pingback]
"http://odin.net/images/pages/52807681/sixteen-inch-penis.html" (http://odin.net... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/xpress-train-hentai-movie.... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/free-mature-bbw-porn.html... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/oral-sex-instruction-pict... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/porn-vagina-sex.html" (ht... [Pingback]
"http://odin.net/images/pages/35694472/council-of-adult-education-australia.html... [Pingback]
"http://odin.net/images/pages/35694472/cartoon-penis.html" (http://odin.net/imag... [Pingback]
"http://odin.net/images/pages/52807681/free-online-porn-samples.html" (http://od... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/teen-gay-sex-totaly-free-... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/collin-farrell-sex-tape.ht... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/xxx-pictures-of-celebrity... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/xxx-hardcore-she-males.ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/straight-guys-fuck-gays-fo... [Pingback]
Archive
<2007 October>
SunMonTueWedThuFriSat
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Cash Foley
Sign In
Statistics
Total Posts: 20
This Year: 0
This Month: 0
This Week: 0
Comments: 5413
Themes
Pick a theme:
All Content © 2017, Cash Foley
DasBlog theme 'Business' created by Christoph De Baene (delarou)