IntelliSearchInstaller.ps1

<#PSScriptInfo
 
.VERSION 1.0.6
 
.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] -Source "IntelliSearch" -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
}