How to create windows service to run a powershell script? How to create windows service to run a powershell script? powershell powershell

How to create windows service to run a powershell script?


Due to the length of the articles I don't want to paste them in the answer.

Check out this post which is the most comprehensive source of info I've found regarding powershell services: https://msdn.microsoft.com/en-us/magazine/mt703436.aspx

which links to an example powershell service: http://jf.larvoire.free.fr/progs/PSService.ps1

I didn't end up successfully modifying this as it was going to take me longer to read through it and understand it than it would to use a different method for my use case, but I'd certainly be going back to that if I needed to create a service in powershell in the future.

Also this: https://www.sapien.com/blog/2017/07/12/write-a-windows-service-in-powershell/


I've been looking all over the place for a decent way to make a PS1 into a service.Easiest way I found is with Winsw:https://github.com/kohsuke/winsw

Works like a charm.


you can create by below step:

  1. First go to the path where PowerShell script located.
  2. Then run below Command:powershell.exe -ExecutionPolicy UnRestricted -File .\filename.ps1