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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.
Defend Against the Q2 Top Security Threats

Were you aware that overall malware worldwide was down a surprising 42% from Q1'18? Every quarter, the WatchGuard Threat Lab releases an Internet Security Report that analyzes the top threat trends impacting companies worldwide. Learn more by viewing our on-demand webinar today!

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!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.