Dynamically generates a small PSService.exe wrapper application, that in turn invokes this PowerShell script.
To create your own service, make a copy of this file and rename it. The file base name becomes the service name. Then implement your own service code in the Service action. There are global settings in config file.
For Service installation and usage help run
Get-Help .\PSService.ps1 -Detailed
The Log function writes messages into a file named
.\Logs\PSService.log
It is very convenient to monitor what's written into that file with
Get-Content -Path ".\Logs\PSService.log" -Wait
Forked from PSService.ps1 from Jean-François Larvoire's GitHub.
The initial version of this script was described in an article published in the May 2016 issue of MSDN Magazine.
This updated version had one major change:
The -Service handler in the end has been rewritten to be event-driven, with a second thread waiting for control messages coming in via a named pipe. This allows fixing a bug of the original version, that did not stop properly, and left a zombie process behind. The drawback is that the new code is significantly longer, due to the added PowerShell thread management routines. On the other hand, these thread management routines are reusable, and will allow building much more powerful services.