title: Changing content in XML file using Powershell
body: <p>Am trying to manipulate an XML file using Powershell.  XML file is 122KB.  When I use the following script, the XML file is then half the size and the service reading the file blows up, but contents are perfect. I'm thinking this is an encoding issue, but not sure how to get around it.  I tried setting the encoding during the set-content, and while I can get the same file size, the NPS service that reads this file doesn't like it.  Opening the file in Notepad++ shows encoding as UCS-2 LE BOM.</p>
  <pre><code>$content = get-content 'C:\Windows\System32\ias\ias.xml'
  $newcontent = $content -replace $oldthumbprint, $newthumbprint
  $newContent | Set-Content 'C:\Windows\System32\ias\ias.xml'
  </code></pre>
  <p>I'm a bit out of my element, so not sure how much of the XML file I should include here.  This is the one particular line I'm changing -</p>
  <pre><code>&lt;Unifi_authentication name=&quot;Unifi authentication&quot;&gt;&lt;Properties&gt;&lt;IP_Filter_Template_Guid xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;string&quot;&gt;{00000000-0000-0000-0000-000000000000}&lt;/IP_Filter_Template_Guid&gt;&lt;Opaque_Data xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;string&quot;&gt;&lt;/Opaque_Data&gt;&lt;Template_Guid xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;string&quot;&gt;{00000000-0000-0000-0000-000000000000}&lt;/Template_Guid&gt;&lt;msEAPConfiguration xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;bin.hex&quot;&gt;190000000000000000000000000000003800000002000000380000000100000014000000e46b7a3127cf1ae043c5336ee1ba33dfbee819800100000001000000100000001a00000000000000&lt;/msEAPConfiguration&gt;&lt;msNPAllowDialin xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;boolean&quot;&gt;1&lt;/msNPAllowDialin&gt;&lt;msNPAllowedEapType xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;bin.hex&quot;&gt;19000000000000000000000000000000&lt;/msNPAllowedEapType&gt;&lt;msNPAuthenticationType2 xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;5&lt;/msNPAuthenticationType2&gt;&lt;msNPAuthenticationType2 xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;3&lt;/msNPAuthenticationType2&gt;&lt;msNPAuthenticationType2 xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;9&lt;/msNPAuthenticationType2&gt;&lt;msNPAuthenticationType2 xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;4&lt;/msNPAuthenticationType2&gt;&lt;msNPAuthenticationType2 xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;10&lt;/msNPAuthenticationType2&gt;&lt;msRADIUSFramedProtocol xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;1&lt;/msRADIUSFramedProtocol&gt;&lt;msRADIUSServiceType xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; dt:dt=&quot;int&quot;&gt;2&lt;/msRADIUSServiceType&gt;&lt;/Properties&gt;&lt;/Unifi_authentication&gt;&lt;/Children&gt;
  </code></pre>
  <p>Any suggestions?</p>