如何使用powershell从xml元素获取变量名

如何使用powershell从xml元素获取变量名,xml,powershell,Xml,Powershell,我想通过powershell从xml中获取要使用的变量。请参阅下面的示例代码 Powershell: $Hostname = (Get-WmiObject Win32_Computersystem).name $IPAddress = ((ipconfig | findstr [0-9].\.)[0]).Split()[-1] $Date=Get-Date -format "yyyy-MM-dd HH:mm:ss" [xml]$ConfigFile = Get-Content "C:\Sett

我想通过powershell从xml中获取要使用的变量。请参阅下面的示例代码

Powershell:

$Hostname = (Get-WmiObject Win32_Computersystem).name
$IPAddress = ((ipconfig | findstr [0-9].\.)[0]).Split()[-1]
$Date=Get-Date -format "yyyy-MM-dd HH:mm:ss"

[xml]$ConfigFile = Get-Content "C:\Settings.xml"

Write-Host $ConfigFile.Management.Printme
XML:


$Hostname |$IPAddress
这只是一个示例代码。我的powershell上有3个变量,我想从xml文件中获取要使用的变量。你能告诉我怎么做吗。正如您所看到的,我上面代码的结果是
$Hostname |$IPAddress
文本,而不是$Hostname和$IPAddress的值。多谢各位


我正在考虑使用-split并将其放到数组中。

使用ExpandString函数:

$ExecutionContext.InvokeCommand.ExpandString($configfile.Management.PrintMe)
$ExecutionContext.InvokeCommand.ExpandString($configfile.Management.PrintMe)