Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. function remove-folder($path) {
  2. remove-item $path -Recurse -Force -ErrorAction SilentlyContinue | out-null
  3. }
  4.  
  5. function generate-from-template($templatePath, $destinationPath, $templateSubstitutions) {
  6. foreach($templateSubstitution in $templateSubstitutions.GetEnumerator()) {
  7. Set-Variable -Name ($templateSubstitution.Name) -Value ($templateSubstitution.Value)
  8. }
  9.  
  10. [System.IO.File]::WriteAllText(
  11. $destinationPath,
  12. $ExecutionContext.InvokeCommand.ExpandString([IO.File]::ReadAllText($templatePath)),
  13. [System.Text.Encoding]::UTF8)
  14. }
  15.  
  16. function argrest($arguments, $index) {
  17. if ($index -ge $arguments.Length) {
  18. return "";
  19. }
  20. return $arguments[$index..($arguments.Length-1)] -join " "
  21. }
  22.  
  23. function info($text) {
  24. Write-Host
  25. Write-Host $text -fore CYAN
  26. Write-Host
  27. }
  28.  
  29. function error($text) {
  30. Write-Host
  31. Write-Host $text -fore RED
  32. Write-Host
  33. }
  34.  
  35. function exec($command, $path) {
  36. if ($null -eq $path) {
  37. $global:lastexitcode = 0
  38. & $command
  39. } else {
  40. Push-Location $path
  41. $global:lastexitcode = 0
  42. & $command
  43. Pop-Location
  44. }
  45.  
  46. if ($lastexitcode -ne 0) {
  47. throw "Error executing command: $command"
  48. }
  49. }
  50.  
  51. function run-self-async {
  52. [string[]] $arguments = @("-File", ".\go.ps1") + ($args | % {'"' + $_ + '"'})
  53.  
  54. Start-Process powershell -ArgumentList $arguments
  55. }
  56.  
  57. function main($mainBlock) {
  58. try {
  59. &$mainBlock
  60. exit 0
  61. } catch [Exception] {
  62. write-host
  63. write-host $_.Exception.Message -fore DARKRED
  64. exit 1
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement