I'm in the process of switching antivirus vendors and need to uninstall the old one remotely. The uninstaller is a straightforward EXE that takes some arguments. Here's a snippet of my PowerShell script: I'm gathering endpoints from a text file and trying to use `Invoke-Command` to connect and run the uninstaller with admin rights. I know that sometimes this can be tricky with permissions. Can anyone advise on the best way to ensure this runs smoothly across multiple machines?
3 Answers
For syntax highlighting in your PowerShell scripts, when posting code here, just indent with tab or spaces to keep things readable. It can make a big difference when others are trying to help! Check out the formatting guide for tips to get it just right, either using plain spaces or backticks for inline code.
Using `Invoke-Command` generally works for elevated access, especially if you're on a domain. Just watch out for instances where it may not elevate, like if you're using local accounts without the right settings. You can check if you're elevated by running `whoami /all` in your script block and looking for a High Mandatory Label.
This issue looks like a classic double hop problem. You might be running as admin on your target machine, but failing to access the file server with the necessary permissions. I recommend copying the uninstaller directly onto the target server first instead of looping through `Invoke-Command`. It speeds things up too. Here's a revised way to do it: first create your directory, then copy your files to each machine, and finally run the uninstallation command with `Invoke-Command`. It should work better that way!
Quick question about the `Invoke-Command` part you mentioned. How do you reference each machine in your script block? Typically, I’d iterate over a list when looping.

I get what you’re saying about double hop issues. I usually run into that when dealing with IIS and SQL Server, but it makes total sense in this context too. I'll try your approach. Thanks for the tip!