Getting error when trying to start windows service through Powershell - powershell

So I am trying to use Powershell to start a windows service. I have the service installed just fine, but when I call Start-Service -Name $name I am recieving the following error.
Start-Service : Service 'IncidentManagementService (IncidentManagementService)' cannot be started due to the following error: Cannot start service IncidentManagementService on computer '.'.
I have powershell running as an Administrator and I also tried going under the properties of the .exe file and checking "run as admin" to no avail.
If anyone could give me a clear reason as to why the service is not starting it would be much appreciated.

In my case the service is disabled... so is the reason I am getting that error.

Related

Cannot start service on computer '.'

I'm trying to create and start a windows service using PowerShell.
The service is created but cannot be started when I use various names besides one particular name.
When I create the service with the name of the exe file it can be started but when I give it a different name it fails to start.
I'm running the PowerShell script as administrator.
Any advises?
function InstallService(
[string] $MsDeployHost,
[string] $ServiceName,
[string] $DisplayName,
[string] $ServicePath,
[string] $ServiceDescription,
[object] $Credential) {
if($MsDeployHost -eq "local") {
New-Service -name $ServiceName -binaryPathName $ServicePath -displayName $ServiceName -StartupType Automatic
Start-Service -name $ServiceName
} else { ....
The Error I get:
Start-Service : Service 'Service1
(Service1)' cannot be started due to the following error:
Cannot start service Service1 on computer '.'.
When I try to start it manually I get:
"Error 1053: The service did not respond to the start or control request in a timely fashion"
The problem is that, unless your service is written to handle it, you need to use a particular service name in order to run a particular service (and note that the name is case-sensitive). This is because the service, on startup, needs to register with the Service Control Manager to receive start/stop notifications and send status updates, using its service name. If you install the service with a different name, but the executable has no way of knowing this (through a configuration setting or whatnot), this registration will fail and the service can't start (to the operating system, it will look as if the service is failing to respond).
You can set the display name to whatever you like, but you cannot use an arbitrary service name unless the service is designed to support this.
My problem was that the service was Disabled in the services control manager.
I then put it in manual state and Start-Service worked.
hth
I had the same problem, for me the issue was that the service was supposed to run with a user's credentials and the user's password has changed - after which the service could not log in anymore and failed to run.
You can review the "Service Control Manager" log, immediately after the failure, like this:
> Get-EventLog -LogName System -Source 'Service Control Manager' -Newest 5
----- ---- --------- ------ ---------- -------
19762 Sep 30 12:31 Error Service Control M... 3221232472 The SERVICE_NAME service failed to start due to the following error: ...
19761 Sep 30 12:31 Error Service Control M... 3221232510 The SERVICE_NAME service was unable to log on as .\USERNAME with the currently configured password due to the following error: ...
#...
> (Get-EventLog -LogName System -Source 'Service Control Manager' -Newest 5)[1] | Format-List
Index : 19764
EntryType : Error
InstanceId : 3221232510
Message : The SERVICE_NAME service was unable to log on as .\USERNAME with the currently configured password due to the following error:
%%1326
To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).
Category : (0)
CategoryNumber : 0
ReplacementStrings : {SERVICE_NAME, .\USERNAME, %%1326}
Source : Service Control Manager
TimeGenerated : 9/30/2021 12:35:02 PM
TimeWritten : 9/30/2021 12:35:02 PM
UserName :
Error 1326 is "Bad username or password".
If this is also a .NET Console Application, you must call ServiceBase.Run in your main method in Program.cs. This fixed this error for me.
See more specific code here:
.NET console application as Windows service
For me it was an incorrect value in appsettings.json. Did not escape some special characters.
This error message is very generic and does not say anything useful.
The reason could be missing configuration files, missing .NET frameworks or anything that the program depends on.
To see the real reason open the Windows event log and look for any errors under Windows Logs -> Application.

Running Start-DscConfiguration gives "the network connection to computername has been interrupted"

I'm running the following cmd locally on the server:
Start-DscConfiguration -computername mycomputer -Path C:\install -Wait -Verbose
The output is:
WARNING: [WSManNetworkFailureDetected] The network connection to
computername has been interrupted. Attempting to reconnect for up to 4
minutes...
It's a new server and I've ran Enable-PSRemoting -Force, and the windows management service is running.
From iprotocol's comment:
You need to start the console with Administrator permission.
I started to get this error and I verified that the problem appeared to be the size of the script: when I commented a part of it, the error would go away.
Searching the web I finally found that the problem was the MOF size (over 500kb).
The solution was to run the following command before running Start-DscConfiguration:
Set-Item WSMan:\localhost\MaxEnvelopeSizekb 1000
The answer was found here: https://powershell.org/forums/topic/dsc-configuration-size/
Note that you may have to use a greater value, depending on your case.

Why would Get-Service not find the service with powershell

I am having problems with a powershell script.
I wrote a script that would search for a windows service with a specific name, and it would Stop or Start this service.
It works when I run it on a server which I log into with a service account that I know that can access the service console. However when it runs off of my build server, the script is no longer able to find the services. I tried giving the service account that runs script the same privaledges as the other service account but that doesn't seem to work.
[System.ServiceProcess.ServiceController]$service = Get-Service -Name $ServiceName -ComputerName $Remoteserver -ErrorAction SilentlyContinue
That is the line that is not longer able to find the service. What am I doing wrong. Is there a way to impersonate a user that can find the service? Any help would be appreciated.
You could try supplying the credentials of the service account using the -Credential parameter. However, since you imply that it used to work with the account that runs the script remotely and no longer does, I think a more likely culprit is that $ServiceName used to only match one service on the target computer, and now there is another service whose name matches that string. If more than one service matches the -Name parameter, Get-Service returns an array of ServiceController objects.
Try running it without ErrorAction -SilentlyContinue. If you get the following error message, then that's what's happening:
Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.ServiceProcess.ServiceController".
If you get a different error message, please add the full error message to the question.

Activate-Feature : Error activating feature <featurename> at siteURl>The located assembly's manifest definition does not match the assembly reference

Error:
Activate-Feature : Error activating feature …<featurename>……… at …<siteURl>……..The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Issue has caused when using PowerShell script to retract and deploy WSP solution, WSP deploys successfully but somehow it get failed to activate a feature with event receiver
I am starting the services as below:
Stop-Service -Name “SPAdminV4”
Start-SPAdminJob
Start-Service -Name SPAdminV4
WaitForSolutionDeploymentJobToFinish $name
Note: I have not found any issue when I do fresh deployment instead retraction/deployment.
I even it works file when I retract the solution in separate script and do deployment with new powershell instance
I have found following references while investigating:
http://sisharepoint.wordpress.com/2010/03/26/getting-around-gac-problems-when-you-deploy-sharepoint-solutions-with-powershell/
http://blogs.msdn.com/b/briangre/archive/2011/02/17/sharepoint-2010-visual-studio-solution-deploy-deployment.aspx
Please guide me to resolve this issue
I have come by this a few times. Unfortunately I have not the time to dive into it further but an application pool recycle seems to fix the issue for me.
i have tried to forcefully restart IIS from Powershell script but that didn't help me... So i have found a workaround i have started a new process from current powershell session and carried out rest of the steps from there. it resolved the issue:
Write-Host "Starting new process"
Start-Sleep 5 Start-Process powershell.exe -ArgumentList '-NoExit','& S:\powersellscript.ps1'
Stop-Process -Id $PID
Close and reopen Visual Studio solve the problem to me.

PowerShell Stop-Service/Start-Service not working on a specific server

I have three servers, let's call them Deploy1, Deploy2, Target.
All servers are running Windows Server 2008R2, fully updated.
A domain user, admin1, is configured as administrator on all servers, and this is the user I'm running all the commands with.
The following command works on Deploy1:
Get-Service "MyService" -ComputerName Target | Stop-Service
When running the same command on Deploy2, the command fails with the following message:
Cannot find any service with service name 'MyService'.
On Deploy2, the following command works, and displays the service and its status.
Get-Service "MyService" -ComputerName Target
Now, I know there are other ways to stop/start services via PowerShell, but I like this one as it automatically waits for the server to actually stop/start.
So what could be wrong with Deploy2?
Powershell v2.0 has a bug (feature?) in how the object returned by Get-Service is implemented. It does not actually set the ComputerName property correctly. Because of this, it can only affect local services. If you upgrade to Windows Management Framework 3.0 (and consequently Powershell v3) the bug is fixed and will work correctly.
Does this work? If not, is there an error produced?
(Get-Service "MyService" -ComputerName Target).Stop()