Jan 13 2023 04:35 AM - edited Jan 13 2023 04:38 AM
I need to create a script that will run an .exe file to uninstall software on a users machine. I have created what I believe to be a simple code to do this, but as the .exe is in a sub folder of the users LOCALAPPDATA, my code only seems to go to the LOCALAPPDATA location and no further.
Can anyone assist in where it is failing?
This is what I have
Start-Process -FilePath $env:LocalAppData +"\**Redact**\update.exe --uninstall -s"
Jan 15 2023 01:47 PM
Jan 16 2023 12:58 AM
PowerShell isn't doing what you think it's doing.
You're expecting it to perform the concatenation of the two strings, then passing the resulting value in as the FilePath value. However, the first thing PowerShell does is parse the parameters, which means only the environment variable is passed in for FilePath, with the rest of the line being assumed to be parameters of some other description.
You should have been getting a helpful error though from PowerShell, as per the example below:
In the second example, you can see where I've used parenthesis to instruct PowerShell to do the concatenation of the string first, before passing the result of that concatenation in as the value for FilePath.
You will then need to split the executable command from the parameters as @Harm_Veenstra has demonstrated above.
Cheers,
Lain
Jan 25 2023 02:07 AM
Jan 25 2023 02:17 AM - edited Jan 29 2023 02:32 AM
SolutionIf my answer solved your issue, please mark it as solution to mark this topic as solved