[xml] question

I’ve created an xml file that contains file paths, some of them being environmental variables.

I’m trying to use the XML to grab and use them but when i take them from the xml it becomes a string, not a cmdlet…is there a way to use them as a command and not a string?

[xml]$spec = get-content .\FILE.xml

$dv = ($spec.techspec.section | ? {$_.systemvalueparameter -eq '$env:SystemRoot'}).systemvalueparameter

so now $dv will equal “$env:systemroot”, but if i test-path $dv it fails…

So $spec.techspec.section contains the name of a cmdlet? If so, you’d just use PowerShell’s Call operator (&), which allows you to execute strings or ScriptBlock objects. For example:

$command = 'Get-Command'

& $command -Name Get-Help -Syntax

No, I’m sorry…I’m explaining this horribly…

$dv = ($spec.techspec.section | ? {$_.systemvalueparameter -eq '$env:SystemRoot'}).systemvalueparameter

This would assign $dv the value of $env:systemroot (which is the value coded into the xml doc on the systemvalueparameter element).

So if I did like a

test-path $dv

It would retrun "False" because it's really doing a test-path '$env:systemroot' instead of a test-path $env:systeroot or test-path "$env:systermroot"

I would like it to return the value of $env:systemroot, not the literal string '$env:systemroot'

It would help if you have an example of your XML document

Oh, I see. There’s a method available in the PowerShell engine to expand variables in strings like that:

$myString = '$env:systemRoot'

$ExecutionContext.InvokeCommand.ExpandString($myString)

Dave! That works like a dream, thanks!