0

Using Powershell, I would like to update Outlook's compatible status to True

<default>
  <application>Excel.exe</application>
  <compatible>True</compatible>

  <application>Outlook.exe</application>
  <compatible>False</compatible>

  <application>Word.exe</application>
  <compatible>False</compatible>
</default>

This post shows how to edit the document if only one 'default.application' instance exists, but the file I am working with has multiple sections named application at that level.

$doc = [xml](Get-Content ./test.xml)

The output of $doc.default.compatible is
True
False
False

How do I modify only the middle value (outlook.exe) to True using Powershell?

Eric
  • 1
  • 1
  • 1
    When I run `$doc.default.application`, I get the name of the application. `$doc.default.compatible` gives me `True False False`. – Davidw Oct 12 '21 at 05:03
  • Sorry, my post is wrong. $doc.default.compatible I've updated the post. – Eric Oct 12 '21 at 06:07

1 Answers1

0

Since you want to change the Compatible Node after the Outlook Node, I implemented to check for it to be the previous value using the PreviousSibling Method before changing value to True.

Updated code:

$docs = [xml](Get-Content ./test.xml)

$doc = $docs.SelectNodes('/default/compatible') 

foreach ($d in $doc){
    if($d.PreviousSibling.OuterXml -eq "<application>Outlook.exe</application>"){
        $d.'#text' = "True"
    }
}

$docs.Save($PSScriptRoot + "\test.xml")