Powershell select and edit node

Hey

How do I select/Edit:  <member key="1" operator="eq" /> under database "000 name" and "HR Huston" (need to change key from 1 to 2)

Using Powershell
 
<roles>
   <role id="{1234}" name="Unit12">
    <databases permission="allow">
      <database name="000 Name" inherit="true">
        <cube name="HR" inherit="true">
          <dimension name="HR Huston" inherit="true">
            <hierarchy name="HR Huston" inherit="true">
              <forcedcriteria>
                <member key="1" operator="eq" />
              </forcedcriteria>
            </hierarchy>
          </dimension>
          <dimension name="HR Boston" inherit="true">
            <hierarchy name="HR Boston" inherit="true">
              <forcedcriteria>
                <member key="2" operator="eq" />
              </forcedcriteria>
            </hierarchy>
          </dimension>
        </cube>
      </database>
  </role>
</roles>
indydkAsked:
Who is Participating?
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.

ste5anSenior DeveloperCommented:
Please rephrase your question. Add the code you have so far. Cause there are too many open questions, e.g. is that XML, where does it come from (file, variable or pipeline).. etc.

But: changing a key means deleting the old row and adding a new row. Keys should be stable and optimally static. So what is you use-case here?
oBdACommented:
It all comes down to the XPath (note that XML is cAsE sEnSiTiVe, including attribute values!):
This works for your sample (with the missing closing "</databases>" node added!).
$xmlPath = '.\test.csv'

$fullPath = (Resolve-Path -Path $xmlPath).Path
$xml = [xml](Get-Content -Path $xmlPath)
$node = $xml.SelectSingleNode('roles/role/databases/database[@name="000 Name"]/cube/dimension[@name="HR Huston"]/hierarchy/forcedcriteria/member')
$node.SetAttribute('key', '2')
$xml.Save($fullPath)

Open in new window

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