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

  • Home
  • SEARCH
  • 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 8532353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:41:47+00:00 2026-06-11T09:41:47+00:00

I am currently writing a PowerShell script that parses an XML file, and it

  • 0

I am currently writing a PowerShell script that parses an XML file, and it saves some parsed values as variables for use later.

For example, say my XML looks like this,

<head>
  <foo>
   <bar id="1" status="dead">
      <baz>
        <qux>Hello World 001</qux>
      </baz>
    </bar>
   <bar>
      <baz>
        <qux>Hello World 002</qux>
       </baz>
   </bar>
  </foo>

  <foo>
   <bar id="2" status="dead">
      <baz>
        <qux>Goodbye World 001</qux>
      </baz>
    </bar>
   <bar>
      <baz>
        <qux>Goodbye World 002</qux>
       </baz>
   </bar>
  </foo>
</head>

Currently, my script looks like this,

[xml]$report = Get-Content ./helloworld.xml
$foo_sub_length = $report.head.foo.length - 1
$bar_sub_length = $report.head.foo[$foo_sub_length].bar.length - 1
$foo_looper = 0
$bar_looper = 0

As of right now, this part works, however, because I would like to pull the id number, or the qux string from each individual foo, I would like to do something similar to the following (pseudocode):

do {
    do {
      $foo($foo_looper)_id = $report.head.foo[$foo_looper].bar[$bar_looper].baz.id
        $foo($foo_looper)_bar($bar_looper)_qux = $report.head.foo[$foo_looper].bar[$bar_looper].baz.qux
      $bar_looper = $bar_looper + 1
    while $bar_looper <= $bar_sub_length
     }
  $foo_looper = $foo_looper + 1
while $foo_looper <= $foo_sub_length
}

I realize this may not have made any sense, or that I may not have been clear, but I would like some assistance. Essentially, is there a way to increment a variable so that it’s name could be, for example, $foo1, $foo2, $foo3, etc, without changing it’s value? Essentially,

> $bar = 1
> $foo($bar) = hello
> $bar + 1
> $foo($bar) = world
> $foo(1)
hello
> $foo(2)
world
  • 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-11T09:41:48+00:00Added an answer on June 11, 2026 at 9:41 am

    Use the New-Variable cmdlet.

    E.g.

    $bar = 1
    New-Variable "foo$bar" "Hello,"
    $bar = $bar + 1
    New-Variable "foo$bar" "World!"
    "$foo1 $foo2"
    

    Should give you

    Hello, World!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently writing a Powershell script that's used to select a user from Active
I am currently writing a Python script for use on Linux machines that will
I am currently writing a simple IOS app that saves tasks into a table.
I am currently writing a script which parses the ServiceTage, Computername and Username from
I'm currently writing some general purpose .net libraries that contain usual helper classes. For
I'm currently writing a script that aims to write Google Calendars for 50 people
I am currently writing some code that can access a separate workbook through an
I am currently writing a deployment script that installs a number of Windows services.
I am currently writing a php script that validates a username and password. I
I'm writing a powershell v2 script that I'd like to run against a remote

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.