title: Calling a Function From Another Function in PowerShell
body: <p>First time in PowerShell 5 and I'm having trouble calling a function that writes messages to a file from another function.  The following is a simplified version of what I'm doing.</p>
  
  <pre><code>workflow test {
      function logMessage {
          param([string] $Msg)
  
          Write-Output $Msg
      }
  
      function RemoveMachineFromCollection{
          param([string]$Collection, [string]$Machine)
  
          # If there's an error
          LogMessage "Error Removing Machine"
  
          # If all is good
          LogMessage "successfully remove machine"
      }
  
  
      $Collections = DatabaseQuery1
  
      foreach -parallel($coll in $Collections) {
          logMessage "operating on $coll collection"
  
          $Machines = DatabaseQuery2
  
          foreach($Mach in $Machines) {
              logMessage "Removing $Mach from $coll"
  
              RemoveMachineFromCollection -Collection $coll -Machine $Mach
          }
      }
  }
  
  test
  </code></pre>
  
  <p>Here's the error it generates:</p>
  
  <pre>
  The term 'logMessage' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      + CategoryInfo          : ObjectNotFound: (logMessage:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
      + PSComputerName        : [localhost]
  </pre>
  
  <p>I've tried moving the logMessage function around in the file and even tried Global scope.</p>
  
  <p>In any other language I would be able to call logMessage from any other function.  As that's the purpose of a function.</p>
  
  <p>What's the "Workflow way" of reusing a block of code?</p>
  
  <p>Do I need to create some logging module that gets loaded into the Workflow?</p>