-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommon.ps1
More file actions
56 lines (52 loc) · 1.52 KB
/
Common.ps1
File metadata and controls
56 lines (52 loc) · 1.52 KB
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
53
54
55
56
function Elevate {
# Elevate powershell environment to Administrator Priviledges,
# which is needed for creating Symbolic Links and Modifying PATH environment variable.
# Reference: https://powershellcommands.com/powershell-elevate-to-admin-in-script
if (-Not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
}
function Log {
param (
[Parameter(Mandatory)]
[string]$Level,
[Parameter(Mandatory)]
[ConsoleColor]$Color,
[Parameter(Mandatory)]
[string]$Message
)
Write-Host "[" -NoNewline
Write-Host "$Level" -ForegroundColor $Color -NoNewline
Write-Host "] $Message"
}
function Error {
param (
[Parameter(Mandatory)]
[string]$Message,
[switch]$Exit
)
Log -Level "ERROR" -Color Red -Message $Message
if ($Exit) {
exit 1
}
}
function Info {
param (
[Parameter(Mandatory)]
[string]$Message
)
Log -Level "INFO" -Color Blue -Message $Message
}
function Source-Script {
param (
[Parameter(Mandatory)]
[string]$Script
)
# `-PathType Leaf` ensures that the script is a file.
if (Test-Path -Path $Script -PathType Leaf) {
. $Script
} else {
Error -Message "Script '$Script' not found." -Exit
}
}