# \[xml\] question

**URL:** <https://forums.powershell.org/t/xml-question/5274>\
**Category:** PowerShell Help\
**Created:** [November 30, 2015, 3:56am UTC](https://forums.powershell.org/t/xml-question/5274 "2015-11-30T03:56:27Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaron-miller](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@aaron-miller](https://forums.powershell.org/u/aaron-miller)\
**Post date:** [November 30, 2015, 3:56am UTC](https://forums.powershell.org/t/xml-question/5274/1 "2015-11-30T03:56:27Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 30, 2015, 4:00am UTC](https://forums.powershell.org/t/xml-question/5274/2 "2015-11-30T04:00:59Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![aaron-miller](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@aaron-miller](https://forums.powershell.org/u/aaron-miller)\
**Post date:** [November 30, 2015, 4:05am UTC](https://forums.powershell.org/t/xml-question/5274/3 "2015-11-30T04:05:22Z")

</div>

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'

---

<div class="post-metadata">

**Author:** ![curtis-smith](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/curtis-smith/32/121_2.png) [@curtis-smith](https://forums.powershell.org/u/curtis-smith)\
**Post date:** [November 30, 2015, 4:07am UTC](https://forums.powershell.org/t/xml-question/5274/4 "2015-11-30T04:07:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [November 30, 2015, 4:10am UTC](https://forums.powershell.org/t/xml-question/5274/5 "2015-11-30T04:10:49Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![aaron-miller](https://avatars.discourse-cdn.com/v4/letter/a/a6a055/32.png) [@aaron-miller](https://forums.powershell.org/u/aaron-miller)\
**Post date:** [November 30, 2015, 4:20am UTC](https://forums.powershell.org/t/xml-question/5274/6 "2015-11-30T04:20:44Z")

</div>

Dave! That works like a dream, thanks!

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:43pm UTC](https://forums.powershell.org/t/xml-question/5274/7 "2024-05-16T20:43:30Z")

</div>


