ExpandString function...


hi gents,

i have data stored in external xml file... script automatically read , assign specific variables.

after while, figured out cannot use variables (%system% or $posh) in external file (which makes complete sense), decided whenever retrieve data, use 2 functions expand sting:

$executioncontext

 

 

.invokecommand.expandstring() expand posh $variables
and
[system.environment]::expandenvironmentvariables() expand system %variables%

it works fine, run problem today while handling sql queries. expandstring() automatically rid of quotes (single or double-quote), sql queries corrupted (where x='y').

i realized can use ''' (where x='''y'''), y cannot variable of course :(

i solved using $([char]39) instead of ', curious how handle such situations?

martin

 maybe?

gc file.xml |%{[regex]::replace($_,"%(\w+)%",'$env:$1')}


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2