title: How to create a function and call it in the same script
body: <p>I need help with creating a function in a script and within that same script calling the function. I have tested this code:</p>
  
  <pre><code>function FUNC1() {
  $source="C:\Folder\file.txt"
  $destination="\\Server\folder"
  $searchFiles = Get-Content "$source"
  foreach($filename in $searchFiles){ 
      Test-Path $destination\$filename 
      }
  }
  
  function FUNC2() {
  $source="C:\Folder\file.txt"
  $destination="\\Server\folder"
  $searchFiles = Get-Content "$source"
  foreach($filename in $searchFiles){ 
      Move-Item C:\folder\$filename $destination -force
      }
  }
  
  if (!(FUNC1)) {FUNC2}
  </code></pre>
  
  <p>However, when testing FUNC1 for false, it does not move anything. When I run the code in the function separately, everything works as it should. Put them together as functions and it is not working. I do not want to create a separate function.ps1 to call, I would rather have my functions called from within the code. Thanks!</p>