How to remove & add a Program using PowerShell command

I'll need to uninstall a software agent on a mass scale (thousands) & then install with another version
as doing so one by one is not feasible.

I have a way to send "Remote PowerShell" commands (though I could send Windows batch ie .bat
commands too but often this run into errors) to the various Windows servers.  Below is the
output of sc queryex of the service & attached the software name (which is an msi file ie uninstall
Agent-Windows-8.0.0-1732.x86_64.msi, Agent-Windows-9.0.0-2004.x86_64.msi
& then reinstall with Agent-Windows-9.0.0-5001.x86_64.msi  )


sc queryex ds_agent

SERVICE_NAME: ds_agent
        TYPE               : 10  WIN32_OWN_PROCESS
        STATE              : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0
DS_RemovePgm.jpg
sunhuxAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sunhuxAuthor Commented:
The installation process will prompt for administrator password & asks to
to confirm to proceed
0
FOXActive Directory/Exchange EngineerCommented:
Sunhux,
I would use psexec with the bat file that you have.  You can run the psexec command against a list of machines inputting your username and password one time and it will hit all those machines with the credentials

https://technet.microsoft.com/en-us/sysinternals/psexec.aspx
0
FOXActive Directory/Exchange EngineerCommented:
put your machinenames in a notepad one beneath the other then name the file with a .txt extenstion
download the pstools to your machine.  cd to the pstools directory that has psexec then run the below

PsExec.exe @\\pathtofilewhosts.txt -u domain\user -p password -c \\pathtobatchfile.txt

(pathtofilewithhosts.txt is the location and filename of your machines)
(pathtobatchfile.txt is the location and filename of your bat file) edit the names to match your scenario
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sunhuxAuthor Commented:
Have used psexec before;  challenge is the installation process will prompt to
confirm to proceed & other prompting
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.