-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall-application.ps1
112 lines (94 loc) · 3.66 KB
/
install-application.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
param(
[Parameter(Mandatory=$False)]
[string[]] $InstallGroups=@()
)
# Application details
$appFilePath = "package\ShellUI_ReactUX_App.mfappx" #TEMPLATED_TODO - Change this to your own packaged app name.
$appGuid = "21cb8d15-da94-4f1c-939c-e4b9e54457be" #TEMPLATED_TODO - Use the newly generated GUID from appdef.xml.
# Target vault
$vaultName = ""
# Connection details
$authType = 1 # 1 = MFAuthTypeLoggedOnWindowsUser
$userName = ""
$password = ""
$domain = ""
$spn = ""
$protocolSequence = "ncacn_ip_tcp"
$networkAddress = "localhost"
$endpoint = 2266
$encryptedConnection = $false
$localComputerName = ""
$ErrorActionPreference = 'Stop'
# Append the current path so we have the full location (required in some situations).
$currentDir = Get-Location
$appFilePath = Join-Path $currentDir $appFilePath
# If we are using install-application.user.json then parse the vault connections.
$vaultConnections = @()
try {
$jsonInput = Get-Content -Path install-application.user.json | ConvertFrom-Json
if($InstallGroups.Count -eq 0) {
Write-Output "No install groups given, proceeding with default"
$InstallGroups += "default"
}
ForEach($jsonConnection in $jsonInput.VaultConnections) {
ForEach($ig in $InstallGroups) {
# if no groups, include to default
if(-not $jsonConnection.installGroups) {
if($InstallGroups -contains "default") {
$vaultConnections += $jsonConnection
Write-Output "$($jsonConnection.vaultName) has no groups - included in default"
}
break; # The connection has no groups, no further looping is needed
}
if($jsonConnection.InstallGroups -contains $ig) {
$vaultConnections += $jsonConnection
Write-Output "$($jsonConnection.vaultName) has group $($ig) - included"
break;
}
}
}
}
catch {
$error.clear();
}
if($vaultConnections.Count -eq 0) {
$vaultConnections += [PSCustomObject]@{
vaultName = $vaultName
authType = $authType
userName = $userName
password = $password
domain = $domain
spn = $spn
protocolSequence = $protocolSequence
networkAddress = $networkAddress
endpoint = $endpoint
encryptedConnection = $encryptedConnection
localComputerName = $localComputerName
}
}
ForEach($vc in $vaultConnections) {
# Load M-Files API
Add-Type -Path 'C:\WINDOWS\assembly\GAC_MSIL\Interop.MFilesAPI\7.0.0.0__f1b4733f444f7ad0\Interop.MFilesAPI.dll'
# Connect to M-Files Server
Write-Host "Connecting to '$($vc.vaultName)' on $($vc.networkAddress)..."
$server = new-object MFilesAPI.MFilesServerApplicationClass
$tzi = new-object MFilesAPI.TimeZoneInformationClass
$tzi.LoadWithCurrentTimeZone()
$null = $server.ConnectAdministrativeEx( $tzi, $vc.authType, $vc.userName, $vc.password, $vc.domain, $vc.spn, $vc.protocolSequence, $vc.networkAddress, $vc.endpoint, $vc.encryptedConnection, $vc.localComputerName )
# Get the target vault
$vaultOnServer = $server.GetOnlineVaults().GetVaultByName( $vc.vaultName )
# Login to vault
$vault = $vaultOnServer.LogIn()
# Try to uninstall existing application
try
{
Write-Host "Checking for previous installation of the application..."
# Uninstall
$vault.CustomApplicationManagementOperations.UninstallCustomApplication( $appGuid );
}
catch {}
# Install application.
Write-Host "Installing application..."
$vault.CustomApplicationManagementOperations.InstallCustomApplication( $appFilePath )
Write-Host "Installation done"
}