SharePoint Updates – Silent Installation using PowerShell

Applies to: SharePoint Server 2016, SharePoint Server 2019

The script looks for the .sts and .wss packages in the same folder where the script is located so do not leave other installation files in the same directory.

Put the script in the same directory as your .sts and .wss files, open the PowerShell as administrator in the same folder and run the script from there. First it will install the .sts and then the .wss package.

It does not stop/suspend the Search Service Application or any other sharepoint service.

If the .sts package requires a reboot to complete the installation it does not have to be done immediately. Therefore the script installs both packages in one go and for each installation it returns “Installation successful”, “Installation failed” or “Reboot Is Required” status. Reboot the server manually if needed.

At the end it also saves the status in the log file in the same location.

#I don not like using $PSScriptRoot..hence the "dot" instead.
$Installationfolder = "."
$InstallSTSandWSSLog = "$Installationfolder\InstallSTSandWSS.txt"

$STSPackage = Get-ChildItem $Installationfolder -Filter *STS*kb*exe | Select-Object -ExpandProperty Name
$WSSPackage = Get-ChildItem $Installationfolder -Filter *WSS*kb*exe | Select-Object -ExpandProperty Name

#Check if installation package is available
if($STSPackage -eq $null -and $WSSPackage -eq $null){Write-Host -ForegroundColor Yellow "There is no installation package in $(get-item "$installationfolder" | select -ExpandProperty fullname)";continue}

#Create the installation log file, overwrite the old one
New-Item -ItemType File $InstallSTSandWSSLog -Force

function Install-Package($Package) {

$startTime = Get-Date

$exitRebootCodes = @(3010, 17022)

#Unblock the package just in case
Get-Item $Package | Unblock-File

#Start the installation of STS Package
Write-Host -ForegroundColor Yellow "Installing $Package..."
Write-Host   'Started:'  $startTime
$process = Start-Process $Package -ArgumentList '/passive /quiet' -PassThru -Wait

$endTime = Get-Date
Write-Host   'Finished:'  $endTime 

Write-Host ("Total time: {0:g}" -f ($endTime - $startTime))

$ExitCode = $process.ExitCode

if ($exitRebootCodes.Contains($ExitCode)){
    $Result =  "Exitcode $Exitcode - Reboot Is Required"} 
        elseif($ExitCode -eq 0){
            $Result = "Exitcode $Exitcode - Installation successful"}
                else {
                    $Result = "Exitcode $Exitcode - Installation failed"}

$obj = [PScustomobject]@{"Package"=$Package;"StartTime"=$startTime;"EndTime"=$endTime;"Result"="$Result";"Duration"=($endTime - $startTime)}
$obj | Select-Object Package,StartTime,EndTime,Duration,Result | Out-File $InstallSTSandWSSLog -Append

Write-Host -ForegroundColor DarkGray ">>>>>>> Result: $Result"


#Install the STS package
Install-Package $STSPackage

#Install The WSS package if it exists
if ($WSSPackage) {
    Install-Package $WSSPackage}

Leave a Reply

Your email address will not be published. Required fields are marked *