Xml powershell

How to open an xml file with powershell.
RIASAsked:
Who is Participating?
 
footechCommented:
I've already shown methods for how to load an xml file.

To save the file you can use
$xml.Save($file)

Open in new window


This link includes info on working with xml files, including how to edit data.
https://www.red-gate.com/simple-talk/sysadmin/powershell/powershell-data-basics-xml/
Exact syntax depends on your xml file.

If you can't provide specifics, then there's nothing more we can contribute here.  Sorry, but you're only providing partial answers to each question.  It's far too much work to provide info to cover every situation, so you need to provide much more detail.
0
 
RIASAuthor Commented:
I am getting this error:
Missing equals sign between attribute and attribute value when I try to
$ObjXmlFile.GetCharArray()
0
 
footechCommented:
There are different ways to open an XML file.
#performs best
$file = "C:\path\to\file.xml"
$xml = New-Object -TypeName System.Xml.XmlDocument
$xml.Load($file)

#or
$file = "C:\path\to\file.xml"
$xml = [xml](Get-Content $file)

# if the file is output from Export-CliXml
$file = "C:\path\to\file.xml"
$xml = Import-CliXml $file

Open in new window


I have no idea where you're getting that error.  You haven't shown what $objxmlfile is.
0
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
RIASAuthor Commented:
Thanks, I am trying to retrieve a xml file which is an webfile.
Using importsocument function
0
 
zvitamConsultantCommented:
$ObjXmlFile.GetCharArray()  is an expression that returns a value.

it should look like:

$a = $ObjXmlFile.GetCharArray()
0
 
RIASAuthor Commented:
Exactly its teturnung the error as mentioned
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Are you able to display the file in e.g. IE as XML?
0
 
footechCommented:
I'm wondering how $ObjXmlFile was actually created/instantiated because GetCharArray() is not a method for the type System.Xml.XmlDocument.  Please show complete (relevant) code.

What exactly are you trying to do?
0
 
RIASAuthor Commented:
Footech,
I am trying to read an xml file and need to edit values in it.
Its a normal xml file and if you could provide me the reference on how to read xml file line by line and alter the values in it , will be very helpful.

Thanks
0
 
RIASAuthor Commented:
Thanks Footech!
0
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.

All Courses

From novice to tech pro — start learning today.