Start-Process not working on remote workstation

All I have the following that is ran on a remote workstation.

Invoke-Command -FilePath .\SysAidUninstall_AddIcon.ps1 -ComputerName $pc
$arg1 = "/c "
$arg2 = "classicuninstall "
$arg3 = "quietmode"

$arg = $arg1 + $arg2 + $arg3

Write-Host "Uninstalling SysAid Agent..."
$service = Get-Service SysAidAgent

if (Get-Service SysAidAgent -ErrorAction SilentlyContinue) {
	if ((Get-Service SysAidAgent).Status -eq "Running") {
		Write-Host "Stopping SysAid Agent Service"
		Stop-Service SysAidAgent
	}
	Write-Host "Uninstalling SysAid Agent"
	Start-Process "C:\Program Files\SysAid\UnInstallAgentUtilities.exe" -ArgumentList $arg

	if (Get-Service SysAidAgent -ErrorAction SilentlyContinue) {
		throw "SysAid Not Uninstalled"
	}
	else {
		Write-Host "SysAid Agent Uninstalled"
		Write-Host "Removing SysAidAgent_17.3.41.0.flag"
		Remove-Item -Path "C:\Windows\Flags\SysAidAgent_17.3.41.0.flag" -Force | Out-Null
	}
}
else {
	Write-Host "SysAid Already Removed."
}

Everything works with the exception of:

Start-Process "C:\Program Files\SysAid\UnInstallAgentUtilities.exe" -ArgumentList $arg

Any thoughts?

What tells you that it isn’t working? E.g., have you monitored the remote process list and don’t see the process starting, or is it not installing whatever it is it’s meant to uninstall?

I am monitoring the remote workstation. It is right beside me. I do see a msiexec start up but does nothing. It almost seems as though the ArgumentList is not being passed correctly to the remote workstation. When I run this on my local machine, it works as it should.

OK, so the command is working, it just isn’t having the desired outcome. It’s entirely possible that the installer isn’t able to run without a user context - e.g., a full profile. That’s super-common in MSIs, and unfortunately there’s not a great way around it. The LCM doesn’t spin up a full user profile, and it’s very, very common for an MSI to want HKEY_CURRENT_USER to exist, along with the other bits of a user profile.

So even though I am logged onto the remote workstation it still will not work when the script is ran remotely?

Windows is a multi-user operating system. The fact that you’re interactively logged into one session has nothing to do with whomever may be connected to other sessions. Remoting isn’t an “interactive” logon; it’s more like connecting to a file share.

Gotcha. Luckily the software I am uninstalling has a very basic file structure and is in only two places in the registry. Here is what I came up with that works. It’s somewhat crude but gets the job done.

Write-Host "Uninstalling SysAid"
Write-Host "==================="
if (Get-Service SysAidAgent -ErrorAction SilentlyContinue) {
	if ((Get-Service SysAidAgent).Status -eq "Running") {
		Write-Host "Stopping SysAid Agent Service"
		Stop-Service SysAidAgent
	}

	$service = Get-WmiObject -Class Win32_Service -Filter "Name='SysaidAgent'"
	$service | Remove-WmiObject
	
	if (Get-Service SysAidAgent -ErrorAction SilentlyContinue) {
		throw "SysAid Service Not Uninstalled"
	}
	
	Write-Host "Removing Registry Keys"
	Remove-Item -Path "HKLM:\SOFTWARE\SysAid" -Recurse -Force | Out-Null
	Remove-Item -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{FC5E1D1D-6D3F-4844-A937-567D589F655E}" -Recurse -Force | Out-Null
	Write-Host "Removing from Program Files"
	Remove-Item -Path "C:\Program Files\SysAid" -Recurse -Force | Out-Null
	
	Write-Host "SysAid Agent Uninstalled"
	Write-Host "Removing SysAidAgent_17.3.41.0.flag"
	Remove-Item -Path "C:\Windows\Flags\SysAidAgent_17.3.41.0.flag" -Force | Out-Null
}
else {
	Write-Host "SysAid Already Removed."
}

Thank you for your guidance.

btw, msiexec works very well if runned as

$PackagePath = 'C:\msipackage.msi' # there should be local path
Invoke-Command -ComputerName $computername { cmd /c start /wait msiexec  /quiet /norestart /i $using:PackagePath }