0

I'm trying to uninstall Palo Alto Traps antivirus from clients using WinRM.

I do know that, correct cmd for that task for silent uninstall is

msiexec /x c:\Traps_x64_4.2.3.41131.msi /quiet /l*v c:\traps_uninstall_log.txt UNINSTALL_PASSWORD=TimeToUninstall!

https://docs.paloaltonetworks.com/cortex/cortex-xdr/5-0/cortex-xdr-agent-admin/traps-agent-for-windows/troubleshoot-traps-for-windows/cytool

But in PowerShell what every I try it just hangs.

I guest its passing those parameters wrong, so the msiexec is trying to open a window but it can't,
because I'm under Enter-PSSession.

Start-Process "msiexec.exe" -ArgumentList "/x Y:\Traps_x64_4.2.3.41131.msi /quiet /l*v c:\traps_uninstall_log.txt UNINSTALL_PASSWORD=TimeToUninstall!" -Wait -PassThru

Do I need to escape some character to work?

Ron
  • 143
  • 4
miharix
  • 133
  • 1
  • 2
  • 6

1 Answers1

1

Running exe when using Powershell is a well-documented thing. Proper quoting is a requirement. How you can the executable is prudent.

TechNet - PowerShell: Running Executables

Start-Process is not the right course is several cases. It's more prudent to just call the installer/exe/msi, et al..

As per the above link, when say targeting cmd.exe:

5. The Call Operator &
Why: Used to treat a string as a SINGLE command. Useful for dealing with spaces.
In PowerShell V2.0, if you are running 7z.exe (7-Zip.exe) or another command that starts with a number, you have to use the command invocation operator &.
The PowerShell V3.0 parser do it now smarter, in this case you don’t need the & anymore.
Details: Runs a command, script, or script block. The call operator, also known as the "invocation operator," lets you run commands that are stored in variables and represented by strings. Because the call operator does not parse the command, it cannot interpret command parameters

Example:
& 'C:\Program Files\Windows Media Player\wmplayer.exe' "c:\videos\my home video.avi" /fullscreen
Things can get tricky when an external command has a lot of parameters or there are spaces in the arguments or paths!
With spaces, you have to nest Quotation marks and the result it is not always clear! 
In this case it is better to separate everything like so:

$CMD = 'SuperApp.exe'
$arg1 = 'filename1'
$arg2 = '-someswitch'
$arg3 = 'C:\documents and settings\user\desktop\some other file.txt'
$arg4 = '-yetanotherswitch'
& $CMD $arg1 $arg2 $arg3 $arg4

# or same like that:
 
$AllArgs = @('filename1', '-someswitch', 'C:\documents and settings\user\desktop\some other file.txt', '-yetanotherswitch')
 
& 'SuperApp.exe' $AllArgs

Or this good article on MSIExec and using Start-Process, taking the same kind of approach.

Powershell: Installing MSI files

$DataStamp = get-date -Format yyyyMMddTHHmmss
$logFile = '{0}-{1}.log' -f $file.fullname,$DataStamp
$MSIArguments = @(
    "/i"
    ('"{0}"' -f $file.fullname)
    "/qn"
    "/norestart"
    "/L*v"
    $logFile
)
Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 

your question though is a common one. See this SU and SO Q&A.

Running msiexec with PowerShell

msiexec.exe /qb /I "C:\myInstaller.msi" INSTALLLOCATION=`"C:\Program Files\installFolder`" ALT_DOC_DIR=`"C:\Program Files\otherFolder`"

How to install .MSI using PowerShell

postanote
  • 4,589
  • 2
  • 7
  • 7