-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap-module.ps1
67 lines (52 loc) · 2.56 KB
/
bootstrap-module.ps1
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
#Download and Run MSI package for Automated install
new-module -name CustomInstaller -scriptblock {
[Console]::OutputEncoding = New-Object -typename System.Text.ASCIIEncoding
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]'Tls,Tls11,Tls12'
function Install-Project {
param (
[Parameter(Mandatory = $true)]
[string]$requiredParam = "THIS_PARAM_IS_REQUIRED",
[string]$optionalParamWithDefault = "https://github.com/Voronenko/ps_oneliners",
[string]$optionalParamFromEnvironment = $env:computername
)
Write-Host "About to execute some bootstrap logic with params $requiredParam $optionalParamWithDefault on $optionalParamFromEnvironment"
Function Download_MSI_Installer {
Write-Host "For example, we download smth from internet"
# Write-Host "About to download $uri to $out"
# Invoke-WebRequest -uri $uri -OutFile $out
# $msifile = Get-ChildItem -Path $out -File -Filter '*.ms*'
# Write-Host MSI $msifile "
}
Function Install_Script {
# $msifile = Get-ChildItem -Path $out -File -Filter '*.ms*'
# $FileExists = Test-Path $msifile -IsValid
$msifile = "c:\some.msi"
$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = '{0}-{1}.log' -f $msifile, $DataStamp
$MSIArguments = @(
"/i"
('"{0}"' -f $msifile)
"/qn"
"/norestart"
"/L*v"
$logFile
" REQUIRED_PARAM=$requiredParam OPTIONAL_PARAM_WITH_DEFAULT=$optionalParamWithDefault OPTIONAL_PARAM_FROM_ENVIRONMENT=$optionalParamFromEnvironment"
)
write-host "About to install msifile with arguments "$MSIArguments
# If ($FileExists -eq $True) {
# Start-Process "msiexec.exe" -ArgumentList $MSIArguments -passthru | wait-process
# Write-Host "Finished msi "$msifile
# }
# Else {
# Write-Error "File $out doesn't exists - failed to download or corrupted. Please check." -ErrorAction Stop
# }
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$PSDefaultParameterValues['*:ErrorAction'] = 'Stop'
Download_MSI_Installer
Install_Script
}
set-alias install -value Install-Project
export-modulemember -function 'Install-Project' -alias 'install'
}