-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.psm1
52 lines (47 loc) · 891 Bytes
/
common.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
$ErrorActionPreference = "Stop"
function Exec
{
param (
[Parameter(Mandatory=$true,Position=0)]
[scriptblock]$Command,
[string]$WorkingDirectory
)
if ($WorkingDirectory) {
Push-Location $WorkingDirectory
}
& $Command
if ($WorkingDirectory) {
Pop-Location
}
Test-LastExitCode
}
function Test-LastExitCode {
if ($LASTEXITCODE -ne 0) {
throw "Operation completed with fail exit code " + $LASTEXITCODE
}
}
function Show-Title {
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Str,
[switch]$SkipNewline
)
if (!$SkipNewline) { Write-Host }
Write-Host $Str -f Yellow
}
function Show-Success {
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Str
)
Write-Host $Str -f Green
}
function Remove-ItemForce {
param (
[Parameter(Mandatory=$true,Position=1)]
[string]$Path
)
if (Test-Path $Path) {
Remove-Item $Path -Recurse -Force
}
}