0
votes

I am just trying to read a simple xml intro a variable in powershell and output values of every child item. I am even following an example and copied every single line of code yet the console wont return anything, as if the .xml was empty.

$XMLfile = 'C:\MyXM.xml'

[xml]$details = Get-Content $XMLfile

foreach($detail in $detail.EmpDetails.Person){
    Write-Host "Employee Id :" $empDetail.Id
    Write-Host "Employee mail Id :" $empDetail.mailId
    Write-Host "Employee Name :" $empDetail.empName
    Write-Host ''
}

the xml looks like the following:

<?xml version="1.0" encoding="ISO-8859-1"?>
<EmpDetails>
    <Person>
        <Id>E00023</Id>
        <mailId>[email protected]</mailId>
        <empName>Aadharsh G.K</empName>     
    </Person>
    <Person>
        <Id>E00042</Id>
        <mailId>[email protected]</mailId>
        <empName>RakshaNivasini S.T</empName>       
    </Person>
</EmpDetails>

The output is just empty. Script gets executed, stops and does nothing.