Self-Updating Powershell Windows Service?

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
EnergySmithe
Posts: 12
Last visit: Thu Sep 14, 2023 6:35 am

Self-Updating Powershell Windows Service?

Post by EnergySmithe »

In my Powershell based utilities I have auto-update built in, so that it updates itself from a network share. It does this with a /version flag which returns the current version string and exits - that is called on a UNC shared copy to determine if it needs to update.

I recently did a short term project that required a windows service, I used the "Windows Service Project" template available in Powershell Studio 5.5.155 and it worked great - it was installed on twelve servers. The only problem was it was a pain to deploy new versions to all the servers...

I have another project and I was trying to work through how to get a windows service to detect if there was an update available and automatically update itself when the service started. That way we could use normal remote calls to restart the service on the servers and they would get the current version when they came back up...

Any thoughts or ideas welcomed... thanks!

Powershell 5.1(+), Powershell Studio 5.5.155
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Self-Updating Powershell Windows Service?

Post by davidc »

If you are using an MSI installer for the service, all you would have to do it download the new MSI and run it (elevated). The MSI should automatically stop the service before updating it.
David
SAPIEN Technologies, Inc.
User avatar
EnergySmithe
Posts: 12
Last visit: Thu Sep 14, 2023 6:35 am

Re: Self-Updating Powershell Windows Service?

Post by EnergySmithe »

The problem would be the same... once it is installed, we do not want to have an admin log into every machine and run something with elevated permissions every time we have an update. In our case we never had to /u then /i the service, we left it registered, stopped the service, copied the files over the top and started the service back up.

The problem is how to facilitate updating of the running file successfully. I was playing with launching a script, and then shutting the service down and then having the script copy the files, but even with some waits I was randomly running into issues with the service still locking the executable file...
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Self-Updating Powershell Windows Service?

Post by davidc »

Depending on the account the service is running, you probably don't need elevation. Have the service download the msi and kick off the install process. The msi installs, it will automatically start up the service for you.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked