Self-Updating Powershell Windows Service?

Ask your Windows 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.
Locked
User avatar
EnergySmithe
Posts: 9
Joined: Wed Jul 08, 2015 8:50 am

Self-Updating Powershell Windows Service?

Post by EnergySmithe » Thu Dec 13, 2018 11:48 am

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: 5839
Joined: Thu Aug 18, 2011 4:56 am

Re: Self-Updating Powershell Windows Service?

Post by davidc » Thu Dec 13, 2018 12:05 pm

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: 9
Joined: Wed Jul 08, 2015 8:50 am

Re: Self-Updating Powershell Windows Service?

Post by EnergySmithe » Thu Dec 13, 2018 1:13 pm

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: 5839
Joined: Thu Aug 18, 2011 4:56 am

Re: Self-Updating Powershell Windows Service?

Post by davidc » Thu Dec 13, 2018 1:51 pm

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.

Locked