Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8947643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:49:03+00:00 2026-06-15T12:49:03+00:00

Can I have some help to add nodes into an existing XML using powershell?

  • 0

Can I have some help to add nodes into an existing XML using powershell?

Here is what I have:

<agentList>
 <newAgent>
      <name>Justice, Kari</name>
      <mu>4690</mu>
  <agentData>
   <group>
       <description>GROUP_DESCRIPTION</description><value>GROUP_NAME</value>
   </group>
  </agentData>
 </newAgent>
</agentList>

and I need to add this:

  <group><description>ACSR System Logon</description><value></value></group>
  <group><description>Current Call Type</description><value></value></group>
  <group><description>OMS</description><value></value></group>
  <group><description>RIO Log-in</description><value></value></group>
  <group><description>Site</description><value></value></group>

Here:

<agentList>
 <newAgent>
      <name>Justice, Kari</name>
      <mu>4690</mu>
  <agentData>
   <group>
       <description>GROUP_DESCRIPTION</description><value>GROUP_NAME</value>
           <====== HERE
           <====== HERE
           <====== HERE
           <====== HERE
   </group>
  </agentData>
 </newAgent>
</agentList>

I may have more than one user on the XML so I was thinking to use the FOREACH line.. but im kinda lost using xml in powershell… If anyone can share some Idea I will be pleased to play with it…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T12:49:04+00:00Added an answer on June 15, 2026 at 12:49 pm

    It should be something along the lines of this:

    $GroupList = @{"Mickey" = "mouse";"Minnie" = "mouse";"Goofy" = "dog"}
    
    $xml=[xml](get-content .\yourfile.xml)
    $xml | Select-Xml -XPath '/agentList/newAgent/agentData' | foreach-object{$_.node.removeall()} #clear group section
    $groupNode = $xml.createelement("group")
    
    foreach ($description in $($GroupList.keys))
    {
        $descNode = $xml.createelement("description")
        $descNode.setattribute("value",$description)
        $groupNode.appendchild($descNode)
    
        $valueNode = $xml.createelement("value")
        $valueNode.setattribute("value",$GroupList[$description])
        $groupNode.appendchild($valueNode)
    }
    
    $xml.selectsinglenode("agentList/newAgent/agentData").appendchild($groupNode)
    $xml.save("C:\YourPathHere\test.xml")
    

    ** This code assumes that the “group” element is already existing in “.\yourfile.xml”.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml file: <A> <B> <elt>Add</elt> ...there are some element here <bId>2</bId>
Can I have some help in improving this linq. I'm basically returning speakers from
Can anyone help? I have some code that is shared between 2 projects. The
can some on help me on how i can reference images i have all
I hope some of you guys can help me with this problem.... I have
We are using Eclipse+CDT+SVN(Linux). How can we have some common header files in a
For my website, I'm considering using Less . Can I have some problem of
i have some Orders that can have several Items and these Items have an
I trying to create inheritance so I can have some super classes with general
I have some items called tickers which can be created and subscribed to. When

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.