Cash Talks - BS Walks RSS 2.0
# Tuesday, 09 October 2007

Powershell provides easy string expansion such as:

$Name = "Cash"
$Msg = "$Name is in the house"

Not too surprising the value of $Msg is "Cash is in the house".

However, what if I want the variable $Msg to be "$Name is in the house" and expand the variable $Name later.  For example, This can be useful for template string.

First, to get the template created you need to suppress the string expansion.

$Msg = '$Name is in the house'

Obviously the Template string has to be properly escaped and ready to evaluate.  Next you have to get Invoke-Expression to expand the variable

$Name = "Cash"
write-host Invoke-Expression ('"' + $Msg + '"')   # - Cash is in the house
$Name = "The Dog"
write-host Invoke-Expression ('"' + $Msg + '"')   # - The Dog is in the house

The explanation is ('"' + $Msg + '"') builds out a string with quotes on both sides ready to be evaluated by Invoke-Expression.

UPDATE

I got slapped down within hours of my first blog posts by The Man.  I'll elevate his comment into my post:

While this technique will work, it's not recommended because of the problem of nested quotes. For example, if your template string was '"$name" is in the house', then you would get an error. PowerShell provides a .NET method to do this directly which is also available to scripts. Here's an example of how to use it:

PS (109) $template = '"$name" is in the house'
PS (110) $name = "Cash"
PS (111) $ExecutionContext.InvokeCommand.ExpandString($template)
Cash is in the house
PS (112) $name = "The dog"
PS (113) $ExecutionContext.InvokeCommand.ExpandString($template)
The dog is in the house

-bruce

=========================================================
Bruce Payette
Principal Developer, Windows PowerShell Team
Microsoft Corporation

Tuesday, 09 October 2007 19:50:06 (GMT Daylight Time, UTC+01:00)  #    Comments [48] -
Powershell
Tracked by:
"http://morningside.edu/mics/_notes/pages/viagra/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/clomid/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/claritin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/prozac/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/melatonin/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/tramadol/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/prilosec/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/cymbalta/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/prilosec/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/wellbutrin/index.html" (http://morning... [Pingback]
"http://blastpr.com/wiki/js/pages/ultram/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/cymbalta/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/celebrex/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/cialis/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/nexium/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/accutane/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/effexor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://morningside.edu/mics/_notes/pages/effexor/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/claritin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/cialis/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/paxil/index.html" (http://morningside.... [Pingback]
"http://blastpr.com/wiki/js/pages/rainbow-brite/index.html" (http://blastpr.com/... [Pingback]
"http://morningside.edu/mics/_notes/pages/coumadin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://blastpr.com/wiki/js/pages/paxil/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/synthroid/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/coumadin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/clomid/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/lexapro/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://morningside.edu/mics/_notes/pages/tramadol/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/celexa/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/hoodia/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/ultram/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/celexa/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/86309858/index.html" (http://vlada... [Pingback]
"http://thebix.com/includes/compat/docs/29852280/index.html" (http://thebix.com/... [Pingback]
"http://jivest2006.com/docs/40579018/index.html" (http://jivest2006.com/docs/405... [Pingback]
"http://ncdtnanotechportal.info/generator/docs/87198700/index.html" (http://ncdt... [Pingback]
"http://witze-humor.de/templates/images/docs/83157240/index.html" (http://witze-... [Pingback]
"http://realestate.hr/templates/css/docs/36157459/index.html" (http://realestate... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/60974094/index.h... [Pingback]
"http://add2rss.com/img/design/docs/90861918/index.html" (http://add2rss.com/img... [Pingback]
"http://ipsilon.hr/ipsilon.hr/cms/4/lib/docs/24066563/index.html" (http://ipsilo... [Pingback]
"http://jivest2006.com/docs/42940613/index.html" (http://jivest2006.com/docs/429... [Pingback]
"http://thebix.com/includes/compat/docs/10152421/index.html" (http://thebix.com/... [Pingback]
"http://martinrozon.com/images/photos/docs/75270452/index.html" (http://martinro... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/08493171/index.html" (http://blog.n... [Pingback]
"http://realestate.hr/templates/css/docs/71546796/index.html" (http://realestate... [Pingback]
"http://martinrozon.com/images/photos/docs/43274485/index.html" (http://martinro... [Pingback]
"http://slaterjohn.com/downloads/2col/28436634/index.html" (http://slaterjohn.co... [Pingback]
"http://lecouac.org/ecrire/lang/docs/30125734/index.html" (http://lecouac.org/ec... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/36483653/index.html" ... [Pingback]
"http://pddownloads.com/docs/21991908/index.html" (http://pddownloads.com/docs/2... [Pingback]
"http://legambitdufou.org/Library/docs/15090396/index.html" (http://legambitdufo... [Pingback]
"http://swellhead.netswellhead.net/docs/84545083/index.html" (http://swellhead.n... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/44378735/index.html" (http://blog.n... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/37348396/index.html" ... [Pingback]
"http://pspdesktops.com/fileupload/store/docs/18769945/index.html" (http://pspde... [Pingback]
"http://thejohnslater.com/pix/img/docs/73486930/index.html" (http://thejohnslate... [Pingback]
"http://witze-humor.de/templates/images/docs/69259068/index.html" (http://witze-... [Pingback]
"http://thebix.com/includes/compat/docs/51589391/index.html" (http://thebix.com/... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/84431573/index.html" (... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/54089144/index.h... [Pingback]
"http://swellhead.netswellhead.net/docs/05235252/index.html" (http://swellhead.n... [Pingback]
"http://entartistes.ca/images/images/docs/65934120/index.html" (http://entartist... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/04726190/index.html" (http://vlada... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/63224938/index.html" ... [Pingback]
"http://discussgod.com/cpstyles/docs/43932298/index.html" (http://discussgod.com... [Pingback]
"http://discussgod.com/cpstyles/docs/62161481/index.html" (http://discussgod.com... [Pingback]
"http://martinrozon.com/images/photos/docs/61904307/index.html" (http://martinro... [Pingback]
"http://vladan.strigo.net/wp-includes/js/docs/09763218/index.html" (http://vlada... [Pingback]
"http://allfreefilms.com/wp-includes/js/27702077/index.html" (http://allfreefilm... [Pingback]
"http://allfreefilms.com/wp-includes/js/25891222/index.html" (http://allfreefilm... [Pingback]
"http://temerav.com/images/menu/91084644/index.html" (http://temerav.com/images/... [Pingback]
"http://coolioness.com/attachments/docs/83777724/index.html" (http://coolioness.... [Pingback]
"http://ncdtnanotechportal.info/generator/docs/13227634/index.html" (http://ncdt... [Pingback]
"http://ipsilon.hr/ipsilon.hr/cms/4/lib/docs/55227677/index.html" (http://ipsilo... [Pingback]
"http://discussgod.com/cpstyles/docs/90092602/index.html" (http://discussgod.com... [Pingback]
"http://plantmol.com/docs/24471383/index.html" (http://plantmol.com/docs/2447138... [Pingback]
"http://ina-tv.sk/img/viagra/" (http://ina-tv.sk/img/viagra/) [Pingback]
"http://sevainc.com/bad_denise/img/10/synthroid/" (http://sevainc.com/bad_denise... [Pingback]
"http://sevainc.com/bad_denise/img/11/ultram/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easycanada.info/js/pages/cialis/" (http://easycanada.info/js/pages/ciali... [Pingback]
"http://easycanada.info/js/pages/viagra/" (http://easycanada.info/js/pages/viagr... [Pingback]
"http://easytravelcanada.info/js/pages/2/celexa/" (http://easytravelcanada.info/... [Pingback]
"http://easytravelcanada.info/js/pages/8/paxil/" (http://easytravelcanada.info/j... [Pingback]
"http://adventure-traveling.com/images/img/viagra/" (http://adventure-traveling.... [Pingback]
"abaffy.org/la/img/viagra/" (abaffy.org/la/img/viagra/) [Pingback]
"http://sevainc.com/bad_denise/img/2/celexa/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://easytravelcanada.info/js/pages/6/lexapro/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/6/lipitor/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/9/rainbow-brite/" (http://easytravelcanad... [Pingback]
"http://easytravelcanada.info/js/pages/2/cialis/" (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/9/rainbow-brite/" (http://sevainc.com/bad_den... [Pingback]
"http://sevainc.com/bad_denise/img/7/melatonin/" (http://sevainc.com/bad_denise/... [Pingback]
"http://easytravelcanada.info/js/pages/10/soma/" (http://easytravelcanada.info/j... [Pingback]
"http://sevainc.com/bad_denise/img/5/effexor/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://sevainc.com/bad_denise/img/4/coumadin/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://sevainc.com/bad_denise/img/1/celebrex/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://jemnemelodierecords.sk/img/cialis/" (http://jemnemelodierecords.sk/img/c... [Pingback]
"http://ina-tv.sk/img/cialis/" (http://ina-tv.sk/img/cialis/) [Pingback]
"http://sevainc.com/bad_denise/img/8/prilosec/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://sevainc.com/bad_denise/img/7/nexium/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://sevainc.com/bad_denise/img/10/soma/" (http://sevainc.com/bad_denise/img/... [Pingback]
"http://sevainc.com/bad_denise/img/3/claritin/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://simpletravelcanada.info/js/pages/27277365/" (http://simpletravelcanada.i... [Pingback]
"http://inatelevizia.sk/ad/img/cialis/" (http://inatelevizia.sk/ad/img/cialis/) [Pingback]
"http://easytravelcanada.info/js/pages/12/zoloft/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/7/melatonin/" (http://easytravelcanada.in... [Pingback]
"http://easytravelcanada.info/js/pages/5/effexor/" (http://easytravelcanada.info... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/adult-free-gay-porn.html" ... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/hentai-spider-man.html" (h... [Pingback]
"http://odin.net/images/pages/35694472/time-square-webcam.html" (http://odin.net... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/black-gay-video-produtions... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/agent-scully-alien-fuck.h... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/federal-judge-sex-scandal-... [Pingback]
"http://odin.net/images/pages/52807681/sexy-co-eds.html" (http://odin.net/images... [Pingback]
"http://odin.net/images/pages/35694472/janet-jackson-bikini.html" (http://odin.n... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/fucking-icons.html" (http:... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/sexual-world-records.html"... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/college-girls-escorts.html... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/free-sex-torrent.html" (ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/index.html" (http://cidesi... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/sex-gadis-melayu.html" (ht... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/st-pauli-girl-distributio... [Pingback]
"http://odin.net/images/pages/35694472/stories-housewives-seducing-husbands-frie... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/porn-vagina-sex.html" (ht... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/porn-star-brooke-banner.h... [Pingback]
"http://odin.net/images/pages/35694472/blondes-and-blacks-xxx.html" (http://odin... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/preview-girls-gone-wild-cl... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/what-is-the-mature-ripene... [Pingback]
"http://odin.net/images/pages/52807681/st-johns-adult-attractions.html" (http://... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/sexy-makeup-pics.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-swim-crest.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/oral-sex-instruction-pict... [Pingback]
"http://odin.net/images/pages/35694472/gay-greger.html" (http://odin.net/images/... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/celebrities-sexy-pictures... [Pingback]
"http://odin.net/images/pages/52807681/free-unlimited-ipod-porn.html" (http://od... [Pingback]
"http://odin.net/images/pages/52807681/men-women-having-sex-together.html" (http... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/teen-nude-school-bus.html... [Pingback]
"http://odin.net/images/pages/52807681/lucy-pinder-michelle-marsh-sex-lessons.ht... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/virgin-vagina-pic.html" (... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/how-do-teen-girls-masturb... [Pingback]
"http://odin.net/images/pages/35694472/hottest-movie-sex-scenes.html" (http://od... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/britney-spears-nude-crotc... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/teen-young-bbw.html" (http... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/free-sex-positions-clips.... [Pingback]
"http://odin.net/images/pages/52807681/britney-no-panties-pics.html" (http://odi... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/a1-thumbnails-posts.html" ... [Pingback]
"http://odin.net/images/pages/52807681/britney-sex-tape-just-a-rumor.html" (http... [Pingback]
"http://odin.net/images/pages/52807681/naruto-hentai.html" (http://odin.net/imag... [Pingback]
"http://odin.net/images/pages/52807681/life-teen-mass-balboa.html" (http://odin.... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-free-preview.html" ... [Pingback]
"http://odin.net/images/pages/35694472/sexy-female-escorts-in-delhi.html" (http:... [Pingback]
"http://odin.net/images/pages/35694472/teen-babysitting-xxx.html" (http://odin.n... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/straight-guys-fuck-gays-fo... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/lisa-rowe-girl-interrupted... [Pingback]
"http://odin.net/images/pages/52807681/hot-girls-squeeze-boobs.html" (http://odi... [Pingback]
"http://odin.net/images/pages/52807681/sexy-thai.html" (http://odin.net/images/p... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/old-film-girl-in-love-with... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/animal-sex-bondage.html" (... [Pingback]
"http://odin.net/images/pages/35694472/candace-von-fuck.html" (http://odin.net/i... [Pingback]
"http://odin.net/images/pages/35694472/pussy-movie-tralers.html" (http://odin.ne... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/what-are-some-sex-hotline... [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)