PS1 to Service: A tool to convert your PS1 to Windows Service on local or other devices
https://www.systanddeploy.com/2020/06/ps1-to-service-tool-to-convert-your-ps1.html
In this post I will show you a tool I created that allows you to create your own Windows Service to run a PowerShell script and specify the delay to run it.
You will be also able to generate scripts and content to create windows service on other devices.
Context
- I wanted to create a Windows Service to run a PowerShell script
- This script allows me to update an app that required admin rights
- Users don't have admin rights
- The service is executed with SYSTEM account
- I didn't want to use solution like SAPIEN for which you have to pay
Note: If you want to display something on the user context, like a GUI, message box, opening notepad... you will need some tricks (like using serviceui.exe).
Indeed, the service is executed in system context.
Get the tool
The tool is available on the below GitHub link:
What you can do ?
The tool allows you to:
- Create a Windows Service locally on the computer executing the tool
- Generate scripts to create service on other devices
How it looks like ?
The tool is divided in two parts:
- Create service locally or generate script content, as below:
- List devices services and their status, as below:
How to use it ?
Create service locally
In the below example I want to:
- Run the script: test.ps1
- Run this script each 5 hours
- Service name: Hey buddy
- Log actions of the service
See below how to proceed:
1. Type the name of your service
2. Type a description
3. Select the PowerShell script to run: here test.ps1
4. Choose the delay to run the sript: here 5
5. Select the delay type, seconds, minutes, hours, days: here hours
7. See below the created Windows Service
8. Log are located in C:\Windows\Debug
9. Service content is created in ProgramData
Generate service content
In the below example I want to:
- Create service on other devices
- Run the script: test.ps1
- Run this script each 5 hours
- Log actions of the service
See how to proceed:
1. Type the name of your service
2. Type a description
3. Select the PowerShell script to run: here test.ps1
4. Choose the delay to run the sript: here 5
5. Select the delay type, seconds, minutes, hours, days: here hours
6. Click on Generate the script
7. Type the path where to save your script content
8. To create the service on other devices, run Create_script.ps1
What's next ?
I will create a PowerShell module to do the same.
2 commentaires
Hello Mr. Damien
Really good post.
It works great on windows 10 but this doesn’t run on windows 7 with .net framework 4.5
Any idea for windows 7?
Hi, I solved updating powershell, because win7 has powershell 2 and I upgraded to 5.1
Enregistrer un commentaire