Sounds like someone needs to write up what they just learned. :) iow, share your new knowledge.
Carl Webster Consultant and Citrix Technology Professional http://www.CarlWebster.com <http://www.carlwebster.com/> On 6/11/12 8:41 AM, "Joseph L. Casale" <[email protected]> wrote: >Much appreciated, it must have been a case of staring at the whole mess >for too long. >I soon resolved the variable expansion, but then cleaned it all up by >passing both hashes >in as args and resolving internal to the dynamic script once at the >remote host. > >Lots of nuances associated with remoting, especially related to getting >results back at the >originating console, its been an adventure. > >Thanks! >jlc > >________________________________________ >From: Michael B. Smith [[email protected]] >Subject: RE: Dynamic ScriptBlock creation > >If you have a hash-table (or any variable that uses text as a 'getter' >for the enumerator) you can use single or double quotes to work around >PowerShell's variable naming conventions. If you are inside a >double-quoted here-string, variable expansion still happens in single >quotes located inside the string. So: > > $objectName = 'someHashTable' > $valueName = 'some-Value-Name' > $resultName = 'resultVariable' > > $here = "`$$resultName = `$$objectName.'$valueName'" > >If you need even more extreme naming conventions, consider this naming >form for your variables, which can also be used to access methods and >properties and special types: > > ${This is a Valid VaRiAbLe Name, with brace decorations!} = 1 > >-----Original Message----- >From: Joseph L. Casale [mailto:[email protected]] >Subject: RE: Dynamic ScriptBlock creation > >The problem stemmed from the fact that I have several modes or operations >that a script may run against several servers. Almost all of the >different operations required some base set of config to be derived by >executing various queries on the remote servers locally. > >All of these jobs required a load of config to be passed into them, I >wrapped invoke-command in a loop that read hosts and their unique >attributes from a file then spawned the jobs. > >Some of these jobs required state information to be passed between them, >but I could not execute the sequence all at once unless each stage was >successful on each node. If a node had an issue, manual intervention >would be required otherwise any node that proceeded would cause the nodes >not passing checks to be invalid and the clusters would be destroyed. So >each step has to be invoked manually. > >I also write state info the successive jobs need to an xml file... > >Burden came when developing the script, the script blocks for each stage >reused code and every change required amending each script block. So I >split them into separate files, set them to vars, and sourced them in one >small script which then assembled them all including the params and state >info into one large script block that is sent to to each node, the single >arg passed in then invokes the required function. > >Thats how I arrived at the exact example I posted, vars changed as they >were meaningless. > >If I use single quotes, how do I perform the substitution? I am also not >sure what you mean by decorated variables, a small nudge would be very >appreciated:) > >Thanks! >jlc >________________________________________ >From: Michael B. Smith [[email protected]] >Subject: RE: Dynamic ScriptBlock creation > >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. ~ 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 [email protected] with the body: unsubscribe ntsysadmin
