-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathInstallGatewayOnLocalMachine.ps1
More file actions
107 lines (86 loc) · 2.98 KB
/
Copy pathInstallGatewayOnLocalMachine.ps1
File metadata and controls
107 lines (86 loc) · 2.98 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
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
#### Here is the usage doc:
#### PS D:\GitHub> .\InstallGatewayOnLocalMachine.ps1 E:\shared\bugbash\IntegrationRuntime.msi <key>
####
param([string]$path, [string]$authKey)
function Install-Gateway([string] $gwPath)
{
# uninstall any existing gateway
UnInstall-Gateway
Write-Host "Start Gateway installation"
Start-Process "msiexec.exe" "/i $path /quiet /passive" -Wait
Start-Sleep -Seconds 30
Write-Host "Succeed to install gateway"
}
function Register-Gateway([string] $key)
{
Write-Host "Start to register gateway with key: $key"
$cmd = Get-CmdFilePath
Start-Process $cmd "-k $key" -Wait
Write-Host "Succeed to register gateway"
}
function Check-WhetherGatewayInstalled([string]$name)
{
$installedSoftwares = Get-ChildItem "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
foreach ($installedSoftware in $installedSoftwares)
{
$displayName = $installedSoftware.GetValue("DisplayName")
if($DisplayName -eq "$name Preview" -or $DisplayName -eq "$name")
{
return $true
}
}
return $false
}
function UnInstall-Gateway()
{
$installed = $false
if (Check-WhetherGatewayInstalled("Microsoft Integration Runtime"))
{
[void](Get-WmiObject -Class Win32_Product -Filter "Name='Microsoft Integration Runtime Preview' or Name='Microsoft Integration Runtime'" -ComputerName $env:COMPUTERNAME).Uninstall()
$installed = $true
}
if (Check-WhetherGatewayInstalled("Microsoft Integration Runtime"))
{
[void](Get-WmiObject -Class Win32_Product -Filter "Name='Microsoft Integration Runtime Preview' or Name='Microsoft Integration Runtime'" -ComputerName $env:COMPUTERNAME).Uninstall()
$installed = $true
}
if ($installed -eq $false)
{
Write-Host "Microsoft Integration Runtime Preview is not installed."
return
}
Write-Host "Microsoft Integration Runtime has been uninstalled from this machine."
}
function Get-CmdFilePath()
{
$filePath = Get-ItemPropertyValue "hklm:\Software\Microsoft\DataTransfer\DataManagementGateway\ConfigurationManager" "DiacmdPath"
if ([string]::IsNullOrEmpty($filePath))
{
throw "Get-InstalledFilePath: Cannot find installed File Path"
}
return $filePath
}
function Validate-Input([string]$path, [string]$key)
{
if ([string]::IsNullOrEmpty($path))
{
throw "Gateway path is not specified"
}
if (!(Test-Path -Path $path))
{
throw "Invalid gateway path: $path"
}
if ([string]::IsNullOrEmpty($key))
{
throw "Gateway Auth key is empty"
}
}
If (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(`
[Security.Principal.WindowsBuiltInRole] "Administrator"))
{
Write-Warning "You do not have Administrator rights to run this script!`nPlease re-run this script as an Administrator!"
Break
}
Validate-Input $path $authKey
Install-Gateway $path
Register-Gateway $authKey