Using Powershell stop multi services.

Dear expert

I would like to know how I write this command in powershell.

I would stop all Services that have service name: Aptic ifront of servicename, for exemple: the name can be: ApticApp1, ApticApp2, all services that got Aptic stop it. if failed stop return a variable $failstop. Services is not on local computer so a network computername or IP is needed.

How do i do? Thanks.
Who is Participating?
oBdAConnect With a Mentor Commented:
Instead of piping the results to Out-GridView, you can pipe them to Export-Csv, Format-Table, or you can remove the "| Out-GridView" at the end, end assign the results to a variable ($Aptic = Get-Service -name ...), and then analyze the variable.
Get-Service -Name Aptic* -ComputerName RemoteMachine | ForEach-Object {
	$result = $_ | Select Name, DisplayName, Status, Result, Error
	Try {
		Stop-Service -InputObject $_ -ErrorAction Stop
		$result.Result = 'STOPPED'
	} Catch {
		$result.Result = 'FAILED'
		$result.Error = $_.Exception.Message
	$result.Status = (Get-Service -InputObject $_).Status
} | Out-GridView

Open in new window

WeTiAuthor Commented:
Hi oBdA

-ComputerName RemoteMachine here if computer in network called: weti, then its -ComputerName weti or -ComputerName \\weti? If i want to use IP instead how to do then?

Just the name, FQDN, or IP address, no backslashes.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

WeTiAuthor Commented:
Great as always, thnx.
WeTiAuthor Commented:
I tried not working tho... no error too
You need to be more precise than "not working".
WeTiAuthor Commented:
oh, I checked, well this PS check for service name, not display name, so display name is Aptic something but service name is something else, is there a way to make powershell check display name of services?
It wouldn't be PowerShell if there weren't.
Just replace -Name in the first line with -DisplayName
WeTiAuthor Commented:
works well, thanks again!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.