-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstall.ps1
120 lines (102 loc) · 3.78 KB
/
Install.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Import-Module .\psfont.psm1
#Set-ConsoleFont 11
##################################### FUNCTIONS ##########################################################################################
function title {
Write-Host "`n*************************************************" -Foreground Red
Write-Host "*`t`tSnipe-IT Installation`t`t*" -Foreground Red
Write-Host "*`t`tInstaller By Madd15`t`t*" -Foreground Red
Write-Host "*************************************************" -Foreground Red
}
function Read-Choice {
Param(
[System.String]$Message,
[Parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[System.String[]]$Choices,
[System.Int32]$DefaultChoice=1,
[System.String]$Title=[string]::Empty
)
[System.Management.Automation.Host.ChoiceDescription[]]$Poss=$Choices | ForEach-Object {
New-Object System.Management.Automation.Host.ChoiceDescription "&$($_)", "Sets $_ as an answer."
}
$Host.UI.PromptForChoice($Title, $Message, $Poss, $DefaultChoice)
}
function Expand-ZIPFile($file, $destination) {
$shell = new-object -com shell.application
$zip = $shell.NameSpace($file)
foreach($item in $zip.items())
{
$shell.Namespace($destination).copyhere($item)
}
}
function Is64Bit {
[IntPtr]::Size -eq 8
}
function installWPI ($prod, $Language) {
}
## IIS Web Platform Installer Variables ##
if (Is64Bit) {
$php = "PHP71x64"
$winCache = "WinCache70x64"
$WPI = "http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi"
}
else {
$php = "PHP71"
$winCache = "WinCache70x86"
$WPI = "http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_x86_en-US.msi"
}
$phpMan = "PHPManager"
#####################################
Clear-Host
title
## Download Web Platform Installer ##
Write-Output "Downloading $WPI"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($WPI, "$PSScriptRoot\wpi.msi")
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
Write-Output "Installing Web Platform Installer"
msiexec.exe /i '$PSScriptRoot\wpi.msi' /passive
## Load Web Platform Installer
try {
[reflection.assembly]::LoadWithPartialName("Microsoft.Web.PlatformInstaller") | Out-Null
Write-Output "Loading Web Platform Installer"
$ProductManager = New-Object Microsoft.Web.PlatformInstaller.ProductManager
$ProductManager.Load()
}
catch {
Write-Error "FATAL ERROR! $($_)"
pause
exit
}
## Install PHP via WPI
try {
Write-Output "Installing PHP via Web Platform Installer"
$product = $ProductManager.Products | Where { $_.ProductId -eq $php }
$InstallManager = New-Object Microsoft.Web.PlatformInstaller.InstallManager
$installer = New-Object 'System.Collections.Generic.List[Microsoft.Web.PlatformInstaller.Installer]'
$Language = $ProductManager.GetLanguage("en")
## Get dependencies
$deplist = New-Object 'System.Collections.Generic.List[Microsoft.Web.PlatformInstaller.Product]'
$deplist.Add($product)
$deps = $product.getMissingDependencies($deplist)
foreach ($dep in $deps) {
$installer.Add($dep.GetInstaller($Language))
Write-Host "Dependency $($dep.Title) found"
}
$installer.Add($product.GetInstaller($Language))
$InstallManager.Load($installer)
#Download the installer package
$failureReason=$null
foreach ($installerContext in $InstallManager.InstallerContexts) {
$InstallManager.DownloadInstallerFile($installerContext, [ref]$failureReason)
Write-Host $($installerContext)
}
$InstallManager.StartSynchronousInstallation()
Write-Host "Installation finished"
}
catch {
Write-Error "FATAL ERROR! $($_)"
pause
exit
}