Powershell XML to CSV script help

Hi

I am able to export a XML file to CSV using the following script

[xml]$XmlDoc=Get-Content -Path C:\powershell\xml\Data.xml
$XmlDoc.EmployeeMasterData.Employee | Export-CSV c:\powershell\csv\doesitwork.csv

Open in new window


What we would like to do is export various tabs Initials, FirstName, LastName, Mail, Mobile, LocationName from the XML to the CSV

XML file

<ns1:EmployeeMasterData xmlns:ns1="http://domain.com/EmployeeMasterdata"><Employee><Initials>ABCDE</Initials><FirstName>Jeannette</FirstName><LastName>fox</LastName><Title>Cordinator</Title><EmployeeNumber>00000015</EmployeeNumber><PersonTypeName>EMPLOYEE</PersonTypeName><Mail>ABCDE@domain.com</Mail><Phone></Phone><Mobile>+4412345678</Mobile><VendorName></VendorName><VendorNumber></VendorNumber><DepartmentName>Tax</DepartmentName><DepartmentNumber>0012345</DepartmentNumber><Office>1CD</Office><LocationName>MIR - Mirum</LocationName><Country>Denmark</Country><SubSystemGroup>Ingen stempling</SubSystemGroup><EvacuationFunction></EvacuationFunction><EvacuationLocation></EvacuationLocation><ResponsiblePerson>00000000</ResponsiblePerson><ResponsiblePersonPhone></ResponsiblePersonPhone><EmploymentDate>2001-02-01T00:00:00Z</EmploymentDate><DepartureDate>9999-12-31T00:00:00Z</DepartureDate><EditedDate>2015-05-07T00:00:00Z</EditedDate><CardNumber>004738092</CardNumber></Employee><Employee><Initials>FGHIJ</Initials><FirstName>Fred</FirstName><LastName>Flintstone</LastName><Title>Chief Man</Title><EmployeeNumber>00000028</EmployeeNumber><PersonTypeName>EMPLOYEE</PersonTypeName><Mail>FGHIJ@domain.com</Mail><Phone></Phone><Mobile>+45123454642</Mobile><VendorName></VendorName><VendorNumber></VendorNumber><DepartmentName>Infrastructure Business</DepartmentName><DepartmentNumber>50002551</DepartmentNumber><Office>BIO</Office><LocationName>LDN - London</LocationName><Country>UK</Country><SubSystemGroup>a load of nonses</SubSystemGroup><EvacuationFunction></EvacuationFunction><EvacuationLocation></EvacuationLocation><ResponsiblePerson>00000000</ResponsiblePerson><ResponsiblePersonPhone></ResponsiblePersonPhone><EmploymentDate>2001-04-01T00:00:00Z</EmploymentDate><DepartureDate>9999-12-31T00:00:00Z</DepartureDate><EditedDate>2015-02-26T00:00:00Z</EditedDate><CardNumber>543541132</CardNumber></Employee></ns1:EmployeeMasterData>
LVL 1
Si WaltonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
Hi,
just select the fields you want to export:
$XmlDoc.EmployeeMasterData.Employee | Select Initials, FirstName, LastName, Mail, Mobile, LocationName | Export-CSV c:\powershell\csv\doesitwork.csv

Open in new window


HTH
Rainer
1
David Johnson, CD, MVPOwnerCommented:
[xml]$XmlDoc=Get-Content -Path C:\temp\employee.xml
$XmlDoc.EmployeeMasterData.Employee | select initials,firstName,Lastname,Mail,Mobile,LocationName | export-csv -nti c:\temp\employee.csv

Open in new window

-nti removes the type information
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Si WaltonAuthor Commented:
Thank you both Solutions worked
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.