Leo Torres
asked on
Powershell Stop Service
I am trying to completely stop this service. But when I try to stop it since its in a stopping state I get the error Below
Here is the code I am using
Stop-Service : Service 'Adaptive Log Exporter (ALE) (AdaptiveLogExporterService)' cannot be stopped due to the following error: Cannot stop AdaptiveLogExporterService
service on computer 'ServerNAme'.
At line:14 char:56
+ Get-Service -ComputerName $Server -Name $StopService | Stop-Service -Verbose -Fo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (System.ServiceProcess.ServiceController:ServiceController) [Stop-Service], ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStopService,Microsoft.PowerShell.Commands.StopServiceCommand
Here is the code I am using
#Test
$ServerList = "ServerName"
$StopService = "AdaptiveLogExporterService"
$ServerArray = $ServerList.split(',');
Foreach( $Server in $ServerArray ){
Get-Service -ComputerName $Server -Name $StopService | Stop-Service -Verbose -Force
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@spraytek: No. But the basic thought is correct, it should be sufficient to just provide a list of servers, without the loop.
Granted, I was thinking too simplistic :)
ASKER
Thanks Qlemo.
You cant do stop Service it didn't work. So I am killing the process.
This worked for me
You cant do stop Service it didn't work. So I am killing the process.
This worked for me
CLS
$ProcessName = "Q1WindowsAgent.exe"
$ServerList = "ServerName"
$ServerArray = $ServerList.split(',');
foreach ($ComputerName in $ServerArray) {
$Process = Get-WmiObject -Class Win32_Process -ComputerName $ComputerName -Filter "name='$ProcessName'"
IF($Process -ne $null) {
$returnval = $process.terminate()
$processid = $process.handle
if($returnval.returnvalue -eq 0) {
write-host "The process $ProcessName `($processid`) terminated successfully on Server $ComputerName"
}
else {
write-host "The process $ProcessName `($processid`) termination has some problems on Server $ComputerName"
}
}
Else {
Write-Host "Process Not Running On Server $ComputerName"
}
}
ASKER
You always provide great help. So I figured I give you points.
Shouldn't that be "ComputerName $ServerList"