# ===================================================================================
# Uninstall-CopyMove.ps1
# (c) SharePoint Products ApS, 2010-2026
#
# CopyMove uninstall 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 = "Uninstalling CopyMove for SharePoint Server Subscription Edition";
$0 = $myInvocation.MyCommand.Definition;
$dp0 = [System.IO.Path]::GetDirectoryName($0);
. "$dp0\Functions.ps1";

Load-SharePoint-Powershell;

Write-Host "Disabling CopyMove farm feature ..." -NoNewline;
$farmFeature = Get-SPFeature -Identity SPPCopyMoveFarm -Farm -ea SilentlyContinue;
if ($farmFeature -ne $null)
{
    Disable-SPFeature -Identity SPPCopyMoveFarm -Confirm:$false;
    Write-Host -f Green " success";
} else
{
    Write-Host -f Yellow " skipped - feature not active";
}

Uninstall-PowerShellModule "SharePointProducts.CopyMove.PowerShell";
Uninstall-PowerShellModule "SharePointProducts.Platform.PowerShell";

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

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

Pause
