Service "--install" fails when ran non-interactively

Hi all,

I’m attempting to deploy a service I created… However, when it is ran as System (as part of an install script), it fails with the error “Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.”

The command I’m using is…

& “.\Service.exe” --install

I get this error when I try to install it via PSRemoting as well. If I RDP into a machine, I can install it just fine.

Anyone else encounter this and work past it?

Hi Jori,

If you could post a complete step-by-step on how to reproduce the issue (that way there’s no need for guessing) with the minimal code then I (and probably others) can try to recreate this and see if we can help.

Hi there, thanks for the response.

So, if I start a powershell window with psexec and attempt to use --install…


Now if I run it from a “normal” admin Powershell window, it works.

I did learn that “New-Service” does work in all scenarios, so that’s what I’ve done to get around this issue.

@DataTraveler @Jori - If we just updated the documentation to suggest New-Service over the --install parameter would that make sense? I have to imagine it’s attempting to perform a similar operation.

That would partially resolve it. --Uninstall has the same problem, but remove-service is not available in Powershell 5.1.

So I’ve had to use the following as the uninstall option…

Get-CimInstance -class win32_service | Where-Object {$_.Name -eq ‘PSEMMT’} | Remove-CimInstance

Ah, good point. I’ll raise an issue for this to see if we can figure out what the issue is.

Awesome. It is a bummer that Remove-Service isn’t available in 5.1…

Out of curiosity, I imported the Microsoft.PowerShell.Management module from Powershell 7 into 5.1 and Remove-Service DID work… But if I had access to Powershell 7 on these machines I wouldn’t have been trying the --install and --uninstall.