title: Trying to pass XML variable to function to update XML file
body: <p>Hi guys (and maybe gals),</p>
  
  <p>In Powershell i'm trying to pass a variable to my function, which I want to use to update a specific node in my XML file. I want to pass the variable $xml.config.server.username (the node in my XML file) to my function and use that to check if it's filled and if it's not filled, fill it with the $Value also passed to the function.</p>
  
  <p>So far I tried this:</p>
  
  <pre><code>function XMLChecker
  (
      [Parameter(Mandatory=$true)] $XMLFile,
      [Parameter(Mandatory=$true)] $Value,
      [Parameter(Mandatory=$true)] $LocationinXML
  )
  
  {
  $XML = New-Object XML
  $XML.load($XMLFile)
  
  if ($LocationinXML -eq "") {
          Write-host "Value $Value is not found in XML file, adding it in the file." -fore Yellow
          $LocationinXML = [string]$Value
          $XML.save("$XMLFile")
          $XML.load("$XMLFile")
      }
  </code></pre>
  
  <p>And to call the function, I tried this:</p>
  
  <pre><code>XMLChecker -XMLFile C:\config.xml -Value "jabadabadoo" -LocationinXML "$xml.config.server.username" -ErrorAction Stop
  </code></pre>
  
  <p>Here is a part of my test XML file:</p>
  
  <pre><code>&lt;config version="1.0"&gt;
    &lt;server dnsname="localhost" ip="127.0.0.1" username="share" /&gt;
  &lt;/config&gt;
  </code></pre>
  
  <p>I'm guessing it is something small which I overlooked (so easy points for you guys :)).</p>