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 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")