IntelliSearchInstaller.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<#PSScriptInfo
 
.VERSION 1.0.5
 
.GUID 98c21248-121d-4066-b6ce-568c55cae511
 
.AUTHOR Nils Kristian Brekke
 
.COMPANYNAME IntelliSearch Software AS
 
.COPYRIGHT 2018 Copyright IntelliSearch Software AS
 
.TAGS IntelliSearch, search, tools
 
.LICENSEURI
 
.PROJECTURI https://www.intellisearch.com/
 
.ICONURI http://www.intellisearch.com/wp-content/uploads/2017/01/Logo-symbol-name-181x50.jpg
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
.PRIVATEDATA
 
#>


<#
 
.DESCRIPTION
 IntelliSearch script for installing a standard IntelliSearch Enterprise File and Mail Search
 
#>
 
[CmdletBinding()]
param (
)

$Old_ErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Stop'

Write-Host "IntelliSearch Core Installer"
Write-Host "The installation is automatic. You do not need"
Write-Host "to interact with it unless prompted to do so.`n"

Write-Host "Preparing setup"

if ($PSVersionTable.PSVersion.Major -lt 5)
{
    Write-Verbose "Creating Get-ItemPropertyValue substitute"
    function Get-ItemPropertyValue()
    {
        Param(
            [Parameter(
                Mandatory = $true,
                Position = 0,
                ValueFromPipeline = $true,
                ValueFromPipelineByPropertyName = $true,
                HelpMessage = "Path to a location."
            )]
            [Alias("PSPath")]
            [ValidateNotNullOrEmpty()]
            [string] $Path,

            [Parameter(
                Mandatory = $true,
                Position = 1,
                ValueFromPipeline = $true,
                ValueFromPipelineByPropertyName = $true,
                HelpMessage = "Name of the property to return value of"
            )]
            [Alias("Property")]
            [ValidateNotNullOrEmpty()]
            [string] $Name
        )

        (Get-ItemProperty -LiteralPath $Path -Name $Name).$Name
    }
}

# Check if the PowerShell PackageManagement module is installed
if (!(Get-Module -ListAvailable "PackageManagement" -Verbose:$false))
{
    Throw "Missing PackageManagement module. Download and install PackageManager from https://www.microsoft.com/en-us/download/details.aspx?id=51451"
}

# Check if correct version of .NET Framework is installed.
if (-not (Get-ChildItem "HKLM:SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\" | Get-ItemPropertyValue -Name Release | ForEach-Object { $_ -ge 461308 }))
{
    Throw "Missing Microsoft .NET Framework 4.7.1. Download and install from https://www.microsoft.com/en-us/download/details.aspx?id=56116"
}

#Install IIS features
$IISFeatures = @(
    'IIS-WebServerRole',
    'IIS-WebServer',
    'IIS-CommonHttpFeatures',
    'IIS-HttpErrors',
    'IIS-HttpRedirect',
    'IIS-ApplicationDevelopment',
    'IIS-NetFxExtensibility',
    'IIS-NetFxExtensibility45',
    'IIS-HealthAndDiagnostics',
    'IIS-HttpLogging',
    'IIS-LoggingLibraries',
    'IIS-RequestMonitor',
    'IIS-HttpTracing',
    'IIS-Security',
    'IIS-RequestFiltering',
    'IIS-Performance',
    'IIS-WebServerManagementTools',
    'IIS-ManagementScriptingTools',
    'IIS-WindowsAuthentication',
    'IIS-StaticContent',
    'IIS-DefaultDocument',
    'IIS-DirectoryBrowsing',
    'IIS-ASPNET',
    'IIS-ASPNET45',
    'IIS-ISAPIExtensions',
    'IIS-ISAPIFilter',
    'IIS-BasicAuthentication',
    'IIS-HttpCompressionStatic',
    'IIS-ManagementConsole',
    'IIS-ManagementService'
)

Write-Host "Verifying and installing IIS features"
foreach ($Feature in $IISFeatures)
{
    if ((Get-WindowsOptionalFeature -Online -Verbose:$false -FeatureNam $Feature).State -ne "Enabled")
    {
        $RequireRestart = $true
        Enable-WindowsOptionalFeature -Online -All -FeatureName $Feature -NoRestart -Verbose:$false | Out-Null
    }
}

if ($RequireRestart)
{
    Write-Warning "Installing some IIS features require a restart. Please restart your computer."
    Write-Warning "Run the installation script again after the computer has been restarted"
    return
}

# Install IntelliSearch PowerShell module
try {
    # If the module is already installed, use Update, otherwise use Install
    if ([bool](Get-Module IntelliSearch -ListAvailable)){
        Remove-Module IntelliSearch -Force -ErrorAction:SilentlyContinue
        Update-Module IntelliSearch -ErrorAction Stop
    } else {
        Install-Module IntelliSearch -Repository PSGallery -Scope AllUsers -ErrorAction Stop -AllowClobber
    }
} catch {
    # But if something went wrong, just -Force it, hard.
    Install-Module IntelliSearch -Repository PSGallery -Scope AllUsers -Force -SkipPublisherCheck -AllowClobber
}

Write-Verbose "Importing IntelliSearch PowerShell module"
Remove-Module powershell-yaml -Force -ErrorAction:SilentlyContinue | Out-Null
Import-Module IntelliSearch -Force -Verbose:$false

#region Add nuget sources
Write-Verbose "Adding NuGet download sources"

$NuGetArgs = @{
    "Add"             = $null
    "Name"            = "IntelliSearch"
    "Source"          = "http://nuget.intellisearch.com/nuget"
    "-NonInteractive" = $null
    "Format"          = "Short"
}

try
{
    Write-Verbose "Adding NuGet feed"
    Invoke-ISNuGetCommand -Action "sources" -Arguments $NuGetArgs | Out-Null
}
catch [System.Management.Automation.RuntimeException]
{
    if (-not ($_.Exception.Message -like "*name specified has already been added*"))
    {  
        Throw $_
    }
}

$Creds = Get-Credential -Message "IntelliSearch NuGet feed credentials"

$NuGetArgs = @{
    "Update"          = $null
    "Name"            = "IntelliSearch"
    "UserName"        = $Creds.UserName
    "Password"        = $Creds.GetNetworkCredential().Password
    "-noninteractive" = $null
    "format"          = "Short"
}
Write-Verbose "Adding credentials to source"
Invoke-ISNuGetCommand -Action "sources" -Arguments $NuGetArgs | Out-Null

#endregion Add nuget sources


$ComponentList = @{
    "CrawlerManager"    = "IntelliSearch.Server.CrawlerManager"
    "FileTransformer"   = "IntelliSearch.Server.FileTransformer"
    "IndexManager1"     = "IntelliSearch.Server.IndexManager"
    "IndexManager2"     = "IntelliSearch.Server.IndexManager"
    "QueueManager"      = "IntelliSearch.Server.QueueManager"
    "SecurityQueue"     = "IntelliSearch.Server.QueueManager"
    "LDAPConnector"     = "IntelliSearch.Connector.LDAP"
    "SearchManager"     = "IntelliSearch.Server.SearchManager"
    "WebClient"         = "IntelliSearch.Client.ENT.Search.ASPNET"
    "FileConnector"     = "IntelliSearch.Connector.File"
    "ExchangeConnector" = "IntelliSearch.Connector.Exchange"
}

Write-Host "Starting installation"
Foreach ($Name in $ComponentList.Keys)
{
    Write-Host ("Installing package '{0}' and configuring as '{1}'`n" -f $ComponentList[$Name], $Name)
    Install-ISComponent -Name $ComponentList[$Name] -PreRelease | New-ISInstance -Name $Name
}

$ErrorActionPreference = $Old_ErrorActionPreference

# Wait for input at end of script
# Check if running Powershell ISE
$PauseMessage = "Installation complete. Press any key to exit."
if ($psISE)
{
    Add-Type -AssemblyName System.Windows.Forms
    [System.Windows.Forms.MessageBox]::Show("$PauseMessage")
}
else
{
    Write-Host "$PauseMessage" -ForegroundColor Yellow
    $host.ui.RawUI.ReadKey("NoEcho,IncludeKeyDown") | Out-Null
}