I'm trying to find the best method to uninstall a software application using PowerShell, specifically for something like Symantec Endpoint. In my current script, I'm using cmd /c to run the UninstallString, but I find that approach a bit clunky. The UninstallString I get from the registry is formatted with odd brackets (`msiexec.exe {XXXX}`) which makes it tricky to directly call it. I know some people suggest using Start-Process with -Arguments as a cleaner solution, but that seems to complicate parsing the uninstall string. What are some less hacky methods or best practices for this?
3 Answers
If you need a dynamic solution, I recommend just running Start-Process with an arguments list without trying to parse the UninstallString too much. You can grab the relevant uninstall strings directly from the registry and execute them. For instance, gather all the UninstallStrings and use a simple loop to call msiexec with the GUIDs. This keeps your code cleaner and avoids the mess of manual string manipulation.
Honestly, the uninstall string can be a pain! I usually either extract the GUID from the string or retrieve it based on the application's display name. For example, you could get the UninstallString, split it to grab just the GUID, and call msiexec. It can take a bit of trial and error, but it avoids unnecessary complications.
There are definitely different ways to uninstall a program! One method is to store the GUIDs of your apps in an array and loop through them. Here's a quick example: you can set your registry key and then iterate through each GUID, checking if it exists before uninstalling it. This way, you're less likely to miss anything. Just remember, this code isn't plug-and-play—it needs to be tweaked to fit your situation.
Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically