0

I want to read element in XML file using parameters. I tried this code, I can print the XML file, but I can't get the element. But I tried to get the element without using parameters and It works.

Param(
  [parameter(mandatory=$true)][string]$XML
)

$Feature= Get-Content $XML
$Feature
$Read_XML = $Feature.DocumentElement.InnerText
$Read_XML

I run the script from cmd :

$PowerShell.exe getxml.ps1 -XML <path xml file>
2
  • It works perfectly. Thanks @OcasoProtal Commented Mar 11, 2019 at 9:46
  • Ok, made it an answer :) Commented Mar 11, 2019 at 9:49

1 Answer 1

1

You need to cast $Feature to xml:

[xml]$Feature= Get-Content $XML
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.