Comparing StdOut to String

I’m using -PassThru with Remove-MsiApplications. I’m then trying to compare StdOut to a string. If they match, perform a function. It’s driving me crazy. The StdOut value has spaces between each character in the string. I adjusted the string I’m comparing to (I copied/pasted the output from StdOut, actually), but it’s still telling me they don’t match.

It’s saying this:T h i s a c t i o n i s o n l y v a l i d f o r p r o d u c t s t h a t a r e c u r r e n t l y i n s t a l l e d .

Doesn’t match:T h i s a c t i o n i s o n l y v a l i d f o r p r o d u c t s t h a t a r e c u r r e n t l y i n s t a l l e d .

Is there some trick to this?

You are doing it wrong. You need to compare the exit code, not the text output. Instead of StdOut use ExitCode. If the msi product is not installed, you will get exit code 1605.

1 Like

I am using the exit code, I was just trying to be sure that I was getting for this particular reason, but I think I might have been confusing it with 1603, which we all know is completely useless.

Thanks. I’ll just stick with If 1605 and go from there.

Yes, you are confusing it with the fatal error code. Just checking for 1605 is the correct way for your scenario.

https://docs.microsoft.com/en-us/windows/win32/msi/error-codes