How to Stop a PowerShell Script From Restarting A Server After Running

Hi All I am running a PowerShell Script to Uninstall VMware Horizon Client on Servers but when it completes the uninstall it automatically restarts the server.

How can I get the script to run and perform the uninstall without automatically restarting the servers?

Below is the script I am using to perform the uninstall.

#####################################Assumed Actions##############################################

This script is running on a computer that is known to have the software we’re looking for on it

##################################################################################################

Code from our “finding the old application script”

$InstalledProduct = Get-WmiObject -Namespace ‘root\cimv2\sms’ -Class SMS_InstalledSoftware
$VMwareHorizonClient = $InstalledProduct | where { ($_.ARPDisplayName -Like ‘VMware Horizon Client’) }

Check out the object to see how we can referencce the LocalPackage (cached MSI)

$VMwareHorizonClient

Create the code to put in our software upgrade script

To make the uninstall silent an extremely common set of switches for the msiexec is /qn (quiet with no interface)

$CachedMSI = $VMwareHorizonClient.LocalPackage

The cached MSI’s Path is always in the LocalPackage property under each instance in SMS_InstalledSoftware

Start-Process ‘msiexec.exe’ -ArgumentList “/x $CachedMSI /qn” -Wait -NoNewWindow

This will be handled best with switches in the MSI arguments.

https://docs.microsoft.com/en-us/windows/win32/msi/standard-installer-command-line-options

Start-Process ‘msiexec.exe’ -ArgumentList “/x $CachedMSI /qn /norestart” -Wait -NoNewWindow