I want to convert XML :
<TEST>
<ipAddress value="10.2.1.90"/>
<gitDir value="C:\git\project"/>
<gitArchiveDir value="C:\git\archive"/>
<apacheDocroot value="/var/www"/>
<apacheUsername value="root"/>
</TEST>
Into a hash table :
Name Value
ipAddress 10.2.1.90
gitDir C:\git\project
gitArchiveDir C:\git\archive
apacheDocroot /var/www
apacheUsername root
Currently using this read method:
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
$File = $directorypath + '\config.xml'
$CONFIG = "CONFIG"
$CFG = [xml] ( gc $File )
$CFG.test.ipAddress
This should do the trick:
PS C:\> $CFG = [xml]@'
>> <TEST>
>> <ipAddress value="10.2.1.90"/>
>> <gitDir value="C:\git\project"/>
>> <gitArchiveDir value="C:\git\archive"/>
>> <apacheDocroot value="/var/www"/>
>> <apacheUsername value="root"/>
>> </TEST>
>> '@
>>
PS C:\> $ht = @{}
PS C:\> $CFG.test.ChildNodes | Foreach {$ht[$_.Name] = $_.Value}
PS C:\> $ht
Name Value
---- -----
apacheUsername root
gitArchiveDir C:\git\archive
ipAddress 10.2.1.90
apacheDocroot /var/www
gitDir C:\git\project
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With