title: Difference between use ''#text'' and InnerText XML (Powershell)
body: <p>I am working on updating some values inside an XML file and I am doing this using PowerShell.
  The XML file is an exported Scheduled Task definition and I am trying to update the value of the Command node, I want to change some part of the path to the program to execute and I am using this code:</p>
  
  <pre><code> 1-|[xml]$taskXmlDefinition = Get-Content -Path $pathXmlTaskDefinition
   2-|$oldCommand = $taskXmlDefinition.Task.Actions.Exec.Command
   3-|$programName = Split-Path -Leaf -Path $oldCommand
   4-|$newCommand =  Join-Path $newPath $programName
   5-|$taskXmlDefinition.GetElementsByTagName("Command")[0].'#text' = $newCommand
   6-|$newTaskXmlFilepath = (Join-Path $newPath $name)
   7-|$taskXmlDefinition.Save($newTaskXmlFilepath)
  </code></pre>
  
  <p>With that code, I am getting this error:
  <a href="https://i.stack.imgur.com/j7h1Z.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/j7h1Z.png" alt="enter image description here"></a></p>
  
  <p>The error is fixed if I change the line 5 for either one of this two:</p>
  
  <pre><code> 5-|$taskXmlDefinition.GetElementsByTagName("Command")[0].'#text' = $newCommand.ToString()
  </code></pre>
  
  <p>or</p>
  
  <pre><code> 5-|[string]($taskXmlDefinition.GetElementsByTagName("Command")[0].'#text') = $newCommand
  </code></pre>
  
  <p>But, I know that if I ask <code>($newCommand).GetType()</code> The result will be <code>System.String</code> and there shouldn't be need to add <code>.ToString()</code></p>
  
  <p>I changed the line (5) for this code:</p>
  
  <pre><code>5-|$taskXmlDefinition.GetElementsByTagName("Command")[0].InnerText = $newCommand
  </code></pre>
  
  <p>and it's working fine. I don't understand the difference or what is going on that I need to make the cast to string explicit.</p>
  
  <p>Can someone explain me the difference in this cases?</p>