Click here to Skip to main content
15,882,811 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have powershell script. I need to run it as a service. I try this way to make it as a service.

What I have tried:

Start-Process -FilePath C:\Users\xx\Downloads\nssm-2.24\win32\nssm.exe -ArgumentList 'install AgentService "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" "-command "& { . D:\SERVICE\Script.ps1}"" ' -NoNewWindow


Then I open run.exe and type services.msc. The service exist. And I try to start it. It show the status is running.

But I see the powershell script is not running. Because in my powershell script I use infinity loop to do some process, like copy and rename file. But It does not work. Anyone can give me idea plese. Thank you.
Posted
Updated 16-Dec-19 21:46pm

1 solution

Here is a way, but it requires some C# knowledge: Windows PowerShell - Writing Windows Services in PowerShell | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900