-
Notifications
You must be signed in to change notification settings - Fork 1
/
Start-LTMSIProcess.psm1
72 lines (68 loc) · 2.24 KB
/
Start-LTMSIProcess.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
function Start-LTMSIProcess
{
<#
.Synopsis
LT helper for starting slient MSI installations.
.DESCRIPTION
Used from starting silent installations with LabTech scripts.
Designed to handle failures and timeout in the event of a hung installation.
.EXAMPLE
Example of how to use this cmdlet
.EXAMPLE
Another example of how to use this cmdlet
#>
Param
(
# Path to the executable.
[Parameter(Mandatory=$true,
ValueFromPipelineByPropertyName=$true,
Position=0)]
[string]
$FilePath,
# Any parameters needed by the executable.
[Parameter(Mandatory=$false,
Position=1)]
[string[]]
$ArgumentList = @(),
# Time out for installation, default is ten minutes in milliseconds.
[Parameter(Mandatory=$false,
Position=2)]
[int32]
$TimeOut = 600000
)
Begin
{
}
Process
{
try
{
$process = Start-Process -FilePath $FilePath -ArgumentList $ArgumentList -PassThru -Wait
$msiProcess = Get-Process msiexec | Sort-Object StartTime | Select-Object -Last 1 #Finds the msi process id.
while(Wait-Process -Id $msiProcess.Id -Timeout $($TimeOut / 1000)) #Converts TimeOut to seconds.
{
Write-Output "The $($FilePath.Substring($FilePath.LastIndexOf('\') + 1)) file installed successfully."
}
}
catch [System.Exception]
{
if($msiProcess.HasExited)
{
Write-Output "The $($FilePath.Substring($FilePath.LastIndexOf('\') + 1)) file did not install, please install manually."
}
else
{
$msiProcess.Kill()
Write-Output "The $($FilePath.Substring($FilePath.LastIndexOf('\') + 1)) file did not install, please install manually."
}
}
if(!$msiProcess.WaitForExit($TimeOut))
{
$msiProcess.Kill()
Write-Output "The $($FilePath.Substring($FilePath.LastIndexOf('\') + 1)) file did not install, please install manually."
}
}
End
{
}
}