Page 1 of 1

Self-Updating Powershell Windows Service?

Posted: Thu Dec 13, 2018 10:48 am
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

Re: Self-Updating Powershell Windows Service?

Posted: Thu Dec 13, 2018 11:05 am
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.

Re: Self-Updating Powershell Windows Service?

Posted: Thu Dec 13, 2018 12:13 pm
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...

Re: Self-Updating Powershell Windows Service?

Posted: Thu Dec 13, 2018 12:51 pm
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.