[英]How to get variable name from xml element using powershell
我想獲取將通過Powershell從xml使用的變量。 請在下面查看我的示例代碼。
電源外殼 :
$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:
<?xml version="1.0"?>
<Management>
<Printme>
$Hostname | $IPAddress
</Printme>
</Management>
這只是一個示例代碼。 我在Powershell上有3個變量,我想從xml文件中獲取要使用的變量。 您能給我一個關於我將如何做的提示。 如您所見,我上面的代碼的結果是$Hostname | $IPAddress
$Hostname | $IPAddress
文本,而不是$ Hostname和$ IPAddress的值。 謝謝。
我正在考慮使用-split並將其放在數組上。
使用ExpandString函數:
$ExecutionContext.InvokeCommand.ExpandString($configfile.Management.PrintMe)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.