Xml powershell

How to open an xml file with powershell.
RIASAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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
RIASAuthor Commented:
Thanks, I am trying to retrieve a xml file which is an webfile.
Using importsocument function
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

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
Qlemo"Batchelor", 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
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

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