util.ps1 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #-------------------------------------------------------------------------------------------------------
  2. # Copyright (C) Microsoft. All rights reserved.
  3. # Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. #-------------------------------------------------------------------------------------------------------
  5. function WriteMessage($str)
  6. {
  7. Write-Output $str
  8. if ($logFile -ne "")
  9. {
  10. Write-Output $str | Out-File $logFile -Append
  11. }
  12. }
  13. function WriteErrorMessage($str)
  14. {
  15. $host.ui.WriteErrorLine($str);
  16. if ($logFile -ne "")
  17. {
  18. Write-Output $str | Out-File $logFile -Append
  19. }
  20. }
  21. function ExecuteCommand($cmd) {
  22. if ($cmd -eq "") {
  23. return;
  24. }
  25. WriteMessage "-------------------------------------"
  26. WriteMessage "Running $cmd"
  27. if ($noaction) {
  28. return;
  29. }
  30. Invoke-Expression $cmd
  31. if($lastexitcode -ne 0) {
  32. WriteErrorMessage "ERROR: Command failed: exit code $LastExitCode"
  33. $global:exitcode = $LastExitCode;
  34. }
  35. WriteMessage ""
  36. }