Cash Talks - BS Walks RSS 2.0
# Wednesday, 12 December 2007

I haven’t posted anything in a while but it’s not because I’ve been idle.  I’ve been doing a massive amount of PowerShell and will be blogging some real cools stuff in the coming weeks.

 

For now, I’m offering a little tidbit I wrote yesterday for reading a file into a binary byte array.  It was necessary for Publishing RDL files in Sequel Server Reporting Services – more on that later too.

 

function read-filebytes($fileItem={Throw "fileItem is required for read-filebytes"})

{

  try {

    [system.io.stream]$stream = [system.io.File]::OpenRead($fileItem.fullname)

    try {

      [byte[]]$filebytes = New-Object byte[] $stream.length

      [void] $stream.Read($filebytes, 0, $stream.Length);

      $filebytes

    } -finally {

      $stream.Close();

    }

  } -catch {

    Write-Error "Error reading file $fileItem - $_"

    return

  }

}

 

I’m using the TryCatchFinally Cmdlet it’s really made error management much easier.

 

The real trick to this script is:

 

  [byte[]]$filebytes = New-Object byte[] $stream.length

 

This pre-allocates the memory for the Stream Read method.  Not a common technique in PowerShell.

 

Cash

Wednesday, 12 December 2007 23:19:29 (GMT Standard Time, UTC+00:00)  #    Comments [38] -
Powershell
Tracked by:
"http://realvideopornoo.com" (http://realvideopornoo.com) [Pingback]
"http://yesihavemoneyy.com" (http://yesihavemoneyy.com) [Pingback]
"http://morningside.edu/mics/_notes/pages/paxil/index.html" (http://morningside.... [Pingback]
"http://blastpr.com/wiki/js/pages/coumadin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/viagra/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/effexor/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/accutane/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/cialis/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/cymbalta/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/wellbutrin/index.html" (http://blastpr.com/wik... [Pingback]
"http://morningside.edu/mics/_notes/pages/hoodia/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/rainbow-brite/index.html" (http://blastpr.com/... [Pingback]
"http://blastpr.com/wiki/js/pages/hoodia/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/clomid/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/tramadol/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/celexa/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/melatonin/index.html" (http://blastpr.com/wiki... [Pingback]
"http://morningside.edu/mics/_notes/pages/lipitor/index.html" (http://morningsid... [Pingback]
"http://morningside.edu/mics/_notes/pages/lexapro/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/celebrex/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/prilosec/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/nexium/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/melatonin/index.html" (http://mornings... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://blastpr.com/wiki/js/pages/nexium/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/clomid/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/prozac/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/prozac/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/lipitor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/cialis/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://add2rss.com/img/design/docs/90861918/index.html" (http://add2rss.com/img... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/87090382/index.h... [Pingback]
"http://legambitdufou.org/Library/docs/64933533/index.html" (http://legambitdufo... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/82710340/index.h... [Pingback]
"http://lecouac.org/ecrire/lang/docs/20007231/index.html" (http://lecouac.org/ec... [Pingback]
"http://temerav.com/images/menu/46200403/index.html" (http://temerav.com/images/... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/54089144/index.h... [Pingback]
"http://slaterjohn.com/downloads/2col/66689432/index.html" (http://slaterjohn.co... [Pingback]
"http://temerav.com/images/menu/20420171/index.html" (http://temerav.com/images/... [Pingback]
"http://realestate.hr/templates/css/docs/36157459/index.html" (http://realestate... [Pingback]
"http://hrvatska.biz/wp-includes/js/docs/80692203/index.html" (http://hrvatska.b... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/91708760/index.html" (http://blog.n... [Pingback]
"http://swellhead.netswellhead.net/docs/42306518/index.html" (http://swellhead.n... [Pingback]
"http://martinrozon.com/images/photos/docs/54373182/index.html" (http://martinro... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/44378735/index.html" (http://blog.n... [Pingback]
"http://pspdesktops.com/fileupload/store/docs/33460308/index.html" (http://pspde... [Pingback]
"http://swellhead.netswellhead.net/docs/92808772/index.html" (http://swellhead.n... [Pingback]
"http://martinrozon.com/images/photos/docs/43274485/index.html" (http://martinro... [Pingback]
"http://discussgod.com/cpstyles/docs/62161481/index.html" (http://discussgod.com... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/84431573/index.html" (... [Pingback]
"http://thebix.com/includes/compat/docs/29852280/index.html" (http://thebix.com/... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/60974094/index.h... [Pingback]
"http://plantmol.com/docs/24471383/index.html" (http://plantmol.com/docs/2447138... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/86309858/index.html" (http://vlada... [Pingback]
"http://lecouac.org/ecrire/lang/docs/25282359/index.html" (http://lecouac.org/ec... [Pingback]
"http://pddownloads.com/docs/94929363/index.html" (http://pddownloads.com/docs/9... [Pingback]
"http://entartistes.ca/images/images/docs/65934120/index.html" (http://entartist... [Pingback]
"http://legambitdufou.org/Library/docs/15090396/index.html" (http://legambitdufo... [Pingback]
"http://discussgod.com/cpstyles/docs/73291253/index.html" (http://discussgod.com... [Pingback]
"http://thejohnslater.com/pix/img/docs/42082955/index.html" (http://thejohnslate... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/37348396/index.html" ... [Pingback]
"http://entartistes.ca/images/images/docs/81367526/index.html" (http://entartist... [Pingback]
"http://thebix.com/includes/compat/docs/44694113/index.html" (http://thebix.com/... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/68291686/index.h... [Pingback]
"http://legambitdufou.org/Library/docs/04618667/index.html" (http://legambitdufo... [Pingback]
"http://jivest2006.com/docs/40579018/index.html" (http://jivest2006.com/docs/405... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/34320152/index.html" (... [Pingback]
"http://thebix.com/includes/compat/docs/10152421/index.html" (http://thebix.com/... [Pingback]
"http://swellhead.netswellhead.net/docs/79619129/index.html" (http://swellhead.n... [Pingback]
"http://slaterjohn.com/downloads/2col/51579700/index.html" (http://slaterjohn.co... [Pingback]
"http://abaffydesign.com/la/img/viagra/" (http://abaffydesign.com/la/img/viagra/... [Pingback]
"http://ina-tv.sk/img/cialis/" (http://ina-tv.sk/img/cialis/) [Pingback]
"http://easytravelcanada.info/js/pages/8/paxil/" (http://easytravelcanada.info/j... [Pingback]
"http://easytravelcanada.info/js/pages/12/viagra/" (http://easytravelcanada.info... [Pingback]
"abaffy.org/la/img/viagra/" (abaffy.org/la/img/viagra/) [Pingback]
"http://birds.sk/img/cialis/" (http://birds.sk/img/cialis/) [Pingback]
"http://sevainc.com/bad_denise/img/11/ultram/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easymexico.info/images/img/cialis/" (http://easymexico.info/images/img/c... [Pingback]
"http://sevainc.com/bad_denise/img/5/effexor/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easytravelcanada.info/js/pages/6/lipitor/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/3/clomid/" (http://easytravelcanada.info/... [Pingback]
"http://easytravelcanada.info/js/pages/1/accutane/" (http://easytravelcanada.inf... [Pingback]
"http://easytravelcanada.info/js/pages/9/rainbow-brite/" (http://easytravelcanad... [Pingback]
"http://sevainc.com/bad_denise/img/12/zoloft/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easycanada.info/js/pages/cialis/" (http://easycanada.info/js/pages/ciali... [Pingback]
"http://sevainc.com/bad_denise/img/7/nexium/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://easytravelcanada.info/js/pages/10/soma/" (http://easytravelcanada.info/j... [Pingback]
"abaffy.org/la/img/cialis/" (abaffy.org/la/img/cialis/) [Pingback]
"http://sevainc.com/bad_denise/img/11/tramadol/" (http://sevainc.com/bad_denise/... [Pingback]
"http://sevainc.com/bad_denise/img/6/lipitor/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easytravelcanada.info/js/pages/12/wellbutrin/" (http://easytravelcanada.... [Pingback]
"http://easytravelcanada.info/js/pages/5/hoodia/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/10/synthroid/" (http://sevainc.com/bad_denise... [Pingback]
"http://easymexico.info/images/img/viagra/" (http://easymexico.info/images/img/v... [Pingback]
"http://easytravelcanada.info/js/pages/2/cialis/" (http://easytravelcanada.info/... [Pingback]
"http://easytravelcanada.info/js/pages/9/prozac/" (http://easytravelcanada.info/... [Pingback]
"http://easytravelcanada.info/js/pages/11/ultram/" (http://easytravelcanada.info... [Pingback]
"http://simplecanada.info/js/pages/13912893/" (http://simplecanada.info/js/pages... [Pingback]
"http://easytravelcanada.info/js/pages/4/coumadin/" (http://easytravelcanada.inf... [Pingback]
"http://easytravelcanada.info/js/pages/6/lexapro/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/7/melatonin/" (http://easytravelcanada.in... [Pingback]
"http://sevainc.com/bad_denise/img/8/prilosec/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://sevainc.com/bad_denise/img/4/coumadin/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://odin.net/images/pages/52807681/sex-women-muscle.html" (http://odin.net/i... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/asian-massage-ct.html" (h... [Pingback]
"http://odin.net/images/pages/35694472/anglina-jolie-nude.html" (http://odin.net... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/adult-porn-comic.html" (ht... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-film-star-listings.... [Pingback]
"http://odin.net/images/pages/52807681/all-fours-thumbnail-naked-girl.html" (htt... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/indian-erotic-sex.html" (h... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/jssica-simpson-fucking.htm... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/baby-pool.html" (http://ci... [Pingback]
"http://odin.net/images/pages/35694472/baby-got-back-by-throwdown.html" (http://... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/barbue-girl.html" (http:/... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/what-are-some-sex-hotline... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/porn-star-brooke-banner.h... [Pingback]
"http://odin.net/images/pages/35694472/free-amauter-porn.html" (http://odin.net/... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/oops-celeb.html" (http://... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/girls-that-lick-ass.html" ... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/teen-gay-sex-totaly-free-... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/vip-adult-clubs.html" (htt... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/nude-fake-celebs-pics.html... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/young-girls-sex-video.html... [Pingback]
"http://odin.net/images/pages/35694472/blondes-and-blacks-xxx.html" (http://odin... [Pingback]
"http://odin.net/images/pages/35694472/kate-winslet-nude-scenes-in-jude.html" (h... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/collin-farrell-sex-tape.ht... [Pingback]
"http://odin.net/images/pages/35694472/babe-tv.html" (http://odin.net/images/pag... [Pingback]
"http://odin.net/images/pages/35694472/should-teens-date-seriously.html" (http:/... [Pingback]
"http://odin.net/images/pages/52807681/sixteen-inch-penis.html" (http://odin.net... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/girl-teen-underwear.html" ... [Pingback]
"http://odin.net/images/pages/52807681/sexy-thai.html" (http://odin.net/images/p... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/free-xxx-3some-pictures-te... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/cheerleader-erotic-stories... [Pingback]
"http://odin.net/images/pages/35694472/index.html" (http://odin.net/images/pages... [Pingback]
"http://odin.net/images/pages/52807681/neosporin-for-anal-fissures.html" (http:/... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/nude-sleeping-sex-xxx.htm... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/sexy-makeup-pics.html" (h... [Pingback]
"http://odin.net/images/pages/52807681/buriram-bar-girls.html" (http://odin.net/... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/nude-celeb-thumbs.html" (... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/index.html" (http://gatew... [Pingback]
"http://odin.net/images/pages/35694472/bikini-calenders.html" (http://odin.net/i... [Pingback]
"http://odin.net/images/pages/35694472/xxx-schoolgirls-hardcore-pictures.html" (... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/adult-synchronized-skate-... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/fucking-stories-for-women... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-bib.html" (http://g... [Pingback]
"http://odin.net/images/pages/52807681/sex-and-deviltry.html" (http://odin.net/i... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/mother-and-daugther-sex-s... [Pingback]
"http://odin.net/images/pages/35694472/cartoon-penis.html" (http://odin.net/imag... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/porn-postcards-free.html" ... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/porn-pictures-of-girls.ht... [Pingback]
"http://odin.net/images/pages/35694472/sexy-native-american-costumes.html" (http... [Pingback]
"http://odin.net/images/pages/52807681/men-women-having-sex-together.html" (http... [Pingback]
"http://odin.net/images/pages/52807681/sex-as-a-suspect-classification.html" (ht... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/mature-fucking-movies.htm... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/erotic-literature-for-wome... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/old-film-girl-in-love-with... [Pingback]
Archive
<2007 December>
SunMonTueWedThuFriSat
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345
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)