jimlong3
(Jim6795)
1
Description
Paying a little back: I often need to start/stop/restart/check some Service or another on a remote PC. Nobody else does that, right?
Well, if you do, rather than reinvent the wheel, here is a small collection of (hopefully useful) scripts I just knocked together. No fancy I/O, just deal with the Service and report its final status. Quick, direct, and it works with v2 and later.
Yeah, you could code this yourself, and probably already have; but now you don’t have to.
I Hope this is helpful!
ETA: There’s nothing stopping you from entering a single letter & “accidentally” stopping or starting ALL the services, so I’d suggest using the “Check” function first & get the full name. I’m working on that so stay tuned. It will no longer be a “small sharp tool”, but at least it will be safe from dingleberries.
Source Code
<########## I put each section in a separate .ps1 file. e.g. "Check-RemoteService.ps1" for the first one:
###########>
<#
Check Status of a Service on a remote PC
#>
$PC = Read-Host "Computer Name ([Enter] to cancel)"
If ($PC) {
$Service = Read-Host "Service Name (any part of the Name, or [Enter] for all)"
If ($Service){"`t" + (Get-Service “*$Service*” -ComputerName $PC).Name + " service on $PC is now " +
(Get-Service “*$Service*” -ComputerName $PC).Status
} else {Get-Service -ComputerName $PC | sort DisplayName | FT Status, Name, DisplayName} # If no Service Name entered
} else {"Cancelling."} # If no PC Name entered
#####################################
<#
Stop a Service on a remote PC
#>
$PC = Read-Host "Computer Name ([Enter] to cancel)"
If ($PC) {
$Service = Read-Host "Service Name (any part of the name)"
$ErrorActionPreference = "SilentlyContinue"
If ($Service){"`tStopping $Service service on $PC"; $svc = Get-Service “*$Service*” -ComputerName $PC ; $svc.Stop()
"`t$($Svc.DisplayName) service on $PC is now " + (Get-Service “*$Service*” -ComputerName $PC).Status}
else {"`tCancelling."} # If no Service Name entered
} else {"Cancelling."} # If no PC Name entered
#######################################
<#
Start a Service on a remote PC
#>
$PC = Read-Host "Computer Name ([Enter] to cancel)"
If ($PC) {
$Service = Read-Host "Service Name (any part of the name)"
$ErrorActionPreference = "SilentlyContinue"
If ($Service){"`tStarting $Service service on $PC"
$svc = Get-Service “*$Service*” -ComputerName $PC ; $svc.Start($True)
"`t$($Svc.DisplayName) service on $PC is now " + (Get-Service “*$Service*” -ComputerName $PC).Status}
else {"`tCancelling."} # If no Service Name entered
} else {"Cancelling."} # If no PC Name entered
#####################################
<#
Restart a Service on a remote PC
#>
$PC = Read-Host "Computer Name ([Enter] to cancel)"
If ($PC) {
$Service = Read-Host "Service Name (any part of the name)"
$ErrorActionPreference = "SilentlyContinue"
If ($Service){"`tRestarting $Service service on $PC"
$svc = Get-Service “*$Service*” -ComputerName $PC ; $svc.Stop() ; $svc.Start($True)
"`t$($Svc.DisplayName) service on $PC is now " + (Get-Service “*$Service*” -ComputerName $PC).Status
} else {"`tCancelling."} # If no Service Name entered
} else {"Cancelling."} # If no PC Name entered
######################################