# ===================================================================================
# Upgrade-Platform.ps1
# (c) SharePoint Products ApS, 2010-2026
#
# SharePoint Products Platform upgrade 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 = "Upgrading SharePoint Products Platform"
$0 = $myInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
. "$dp0\Functions.ps1"

Load-SharePoint-Powershell

Write-Host "- Restarting services on all servers in the farm to release any file locks on the CopyMove assemblies"
$ServiceNames=@("SPTimerV4","SPAdminV4","IISADMIN","W3SVC", "OSearch15")
ResetServicesOnAllServers $ServiceNames

Write-Host "- Upgrading solution"
UpgradeFarmSolution "sharepointproducts_platform.wsp" "$dp0\..\sharepointproducts_platform.wsp";

Write-Host "- Restarting the Timer Service again on all servers"
$ServiceNames=@("SPTimerV4")
ResetServicesOnAllServers $ServiceNames

Write-Host "- Enabling SPPPlatformFarm feature"
Enable-SPFeature -Identity SPPPlatformFarm -Force

Pause

