title: PowerShell and global functions
body: <p>Why is the following code not working? According to this article the usage of global should be correct: <a href="http://technet.microsoft.com/en-us/library/ff730957.aspx" rel="nofollow">http://technet.microsoft.com/en-us/library/ff730957.aspx</a></p>
  
  <pre><code>Function global:writeLog {
      param($logType, $logString, $logFile)
  
      $fileStream = New-Object IO.FileStream $logFile ,'Append','Write','Read'
      $streamWriter = New-Object System.IO.StreamWriter $fileStream
  
      $time = get-date -Format "hh:mm:ss"
      $streamWriter.writeLine("[${time}][$logType] ${logString}")
  
      $streamWriter.close()
  
  }
  
  $temp = {
      writeLog -logType "INFO" -logString "Test" -logFile "d:\scripts\powershell\logtest.txt"
  }
  
  Start-Job -ScriptBlock $temp 
  get-job | receive-job -AutoRemoveJob -Wait
  </code></pre>
  
  <p>This is the exception that powershell throws</p>
  
  <pre><code>The term 'writeLog' 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: (writeLog:String) [], CommandNotFoundException
      + FullyQualifiedErrorId : CommandNotFoundException
      + PSComputerName        : localhost
  </code></pre>