There are likely 2 or 3 ways to address this (using single quotes or decorated variables), but I'd really like to see an real-world example, 'cuz it's not clear to me what you are trying to accomplish.
And, by the way, scriptblocks are always serialized as strings - so you may not actually be helping yourself. -----Original Message----- From: Joseph L. Casale [mailto:jcas...@activenetwerx.com] Sent: Friday, June 08, 2012 6:00 PM To: NT System Admin Issues Subject: Dynamic ScriptBlock creation To overcome some difficulties in passing args and combining script blocks to be sent to multiple hosts, I am using [ScriptBlock]::Create() on a few existing ScriptBlocks and one text here string to populate variables in the ScriptBlock instead of passing args. My issue is expanding certain variable types in the here string: This doesn't work, only $var1 expands out to create a valid string representation of a ScriptBlock for later conversion: $ScriptBlockArgs = @" `$foo = `"$PSCustomObject."KeyName"`" `$bar = `"$var1`" "@ This does work, but is likely unnecessary: $var0 = $Node."Instance-Name" $ScriptBlockArgs = @" `$foo = `"$var0`" `$bar = `"$var1`" "@ I realize the double quotes on KeyName are an issue, but I have tried everything I can think of to escape or pre expand it without success. It also bails when trying to assign a hash table into a new variable. Anyone have any ideas? Thanks. jlc ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ <http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/> ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin