util.ps1 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  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. Write-Output $str
  7. if ($logFile -ne "") {
  8. Write-Output $str | Out-File $logFile -Append
  9. }
  10. }
  11. function WriteErrorMessage($str) {
  12. $host.ui.WriteErrorLine($str);
  13. if ($logFile -ne "") {
  14. Write-Output $str | Out-File $logFile -Append
  15. }
  16. }
  17. function ExecuteCommand($cmd) {
  18. if ($cmd -eq "") {
  19. return;
  20. }
  21. WriteMessage "-------------------------------------"
  22. WriteMessage "Running $cmd"
  23. if ($noaction) {
  24. return;
  25. }
  26. Invoke-Expression $cmd
  27. if($lastexitcode -ne 0) {
  28. WriteErrorMessage "ERROR: Command failed: exit code $LastExitCode"
  29. $global:exitcode = $LastExitCode;
  30. }
  31. WriteMessage ""
  32. }