-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathBtsSetupHelper.psm1
101 lines (80 loc) · 2.75 KB
/
BtsSetupHelper.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#Requires -RunAsAdministrator
function Check-32Bit
{
if ($env:PROCESSOR_ARCHITECTURE -ne "x86")
{
$scriptInvocation = (Get-Variable MyInvocation -Scope 1).Value
$errorText = "The script $($scriptInvocation.MyCommand) must run in a 32 bit PowerShell Host. Found architecture $env:PROCESSOR_ARCHITECTURE"
Write-Error $errorText
Exit
}
}
function Check-64Bit
{
if ($env:PROCESSOR_ARCHITECTURE -eq "x86")
{
$scriptInvocation = (Get-Variable MyInvocation -Scope 1).Value
$errorText = "The script $($scriptInvocation.MyCommand) must run in a 64 bit PowerShell Host. Found architecture $env:PROCESSOR_ARCHITECTURE"
Write-Error $errorText
Exit
}
}
function Prompt-YesNo ($title,$message, $yesText, $noText)
{
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", $yesText
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No", $noText
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$result = $host.ui.PromptForChoice($title, $message, $options, 0)
return $result -eq 0
}
function Get-ScriptDirectory
{
$scriptInvocation = (Get-Variable MyInvocation -Scope 1).Value
return Split-Path $scriptInvocation.MyCommand.Path
}
function Log-SetupStep ($message, [ValidateSet('Information','Warning','Error')]$level )
{
$timestamp = [System.DateTime]::Now.ToString("yyyy-MM-dd HH:mm:ss")
switch ($level)
{
'Warning'
{
Write-Host "$timestamp $message" -ForegroundColor DarkYellow
}
'Error'
{
Write-Host "$timestamp $message" -ForegroundColor Red
}
Default
{
Write-Host "$timestamp $message" -ForegroundColor Gray
}
}
}
function Load-ConfigFile($fullPathToFile, [switch]$exitOnError )
{
Log-SetupStep -message "Start Load-ConfigFile $fullPathToFile" -level Information
if ((Test-Path -Path $fullPathToFile)-eq $false )
{
if ($exitOnError)
{
Log-SetupStep -message "Load-ConfigFile '$fullPathToFile' Not found. Quit selected." -level Error
Exit
}
else
{
Log-SetupStep -message "Load-ConfigFile '$fullPathToFile' Not found." -level Warning
return $null
}
}
else
{
$configuration = Get-Content $fullPathToFile -Encoding UTF8 | ConvertFrom-Csv -Delimiter ";"
return $configuration
}
Log-SetupStep -message "End Load-ConfigFile $fullPathToFile" -level Information
}
################################################################
# Maincode
################################################################