# ===================================================================================
# Install-CopyMove.ps1
# (c) SharePoint Products 2010-2022
#
# CopyMove install script
# ===================================================================================

$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent();
$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID);
$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator;
if ($myWindowsPrincipal.IsInRole($adminRole))
{
	$Host.UI.RawUI.BackgroundColor = "DarkBlue";
	Clear-Host;
} else
{
    $arguments = $myInvocation.MyCommand.Definition;
    Start-Process powershell.exe -Verb RunAs -ArgumentList "-file `"$arguments`"";
    exit;
}

$Host.UI.RawUI.WindowTitle = "Installing CopyMove for SharePoint Server Subscription Edition";
$0 = $myInvocation.MyCommand.Definition;
$dp0 = [System.IO.Path]::GetDirectoryName($0);
. "$dp0\Functions.ps1";

Load-SharePoint-Powershell;

Create-EventSource "SharePoint Products";

Add-FarmSolution "$dp0\..\sharepointproducts_platform.wsp";
Add-FarmSolution "$dp0\..\sharepointproducts_copymove.wsp";

Install-FarmSolution "sharepointproducts_platform.wsp";
Install-FarmSolution "sharepointproducts_copymove.wsp";

Write-Host "Enabling CopyMove farm feature ..." -NoNewline;
start -NoNewWindow -Wait powershell {
	$PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue;
	Enable-SPFeature -Identity SPPCopyMoveFarm;
}
Write-Host -f Green " success";

Install-PowerShellModule "$dp0\..";

Write-Host ""
Write-Host "Installation complete - configure CopyMove as follows:"
Write-Host "1. Navigate to 'Central Administation -> Manage farm features'"
Write-Host "2. Ensure that the feature 'CopyMove for SharePoint Server SE' is activated"
Write-Host "3. Activate the CopyMove site collection feature feature on all applicable site collections"
Write-Host "4. Optionally change default settings from 'Central Administration -> CopyMove settings'"
Write-Host "5. Done"
Write-Host ""

Pause

