PowerShell provides an easy way to get services on Windows
operating system.
The cmdlet to get services on Windows is quite simple, just
type: Get-Service
To filter out running or stopped services type this command
below:
Get-Service | Where-Object {$_.Status -match 'Running'}
Get-Service | Where-Object {$_.Status -match 'Stopped'}
To check the status for a particular service, type this
command below:
$xService = Get-Service 'BFE'
write-output $xService
Output of the command above:
Status Name DisplayName
------ ----
-----------
Running BFE Base
Filtering Engine
To get a specific column from the output, specify the column
number.
$outputx = Get-Service 'BFE' | Format-Wide -Property Status -Column 1
$outputx = Get-Service 'BFE' | Format-Wide -Property Status -Column 1
Write-Output $outputx
or use this command below: (see comments below from Jeffrey Snover)
Thanks Jeff!
$outputx = (Get-Service 'BFE').Status
It will only display whatever is
the status result for the particular service specified.
On this example, since the status is running, so the output will only be:
Running
To start or stop a service, the command has to be run on an
elevated PowerShell.
Starting and stopping a service without elevation will
result to an error.
Error message will be similar to this:
Start-Service : Service 'Windows Service Name' cannot be
started due to the following error: Cannot open Service Name service on
computer '.'.
Anyway once the PowerShell is elevated, run this simple
command to start and stop a service:
$xService = "W32Time"
$xService = "W32Time"
Stop-Service $xService
Or:
Start-Service $xService
Cheers!! Till next time..
-----------------------------------------
Linux Android App cheat sheet:
https://play.google.com/store/apps/details?id=com.LinuxMobileKit
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
https://play.google.com/store/apps/details?id=com.myrosaryapp
-----------------------------------------
Linux Android App cheat sheet:
https://play.google.com/store/apps/details?id=com.LinuxMobileKit
https://play.google.com/store/apps/details?id=soulrefresh.beautiful.prayer
Catholic Rosary Guide for Android:
https://play.google.com/store/apps/details?id=com.myrosaryapp
Consider changing this:
ReplyDelete$outputx = Get-Service 'BFE' | Format-Wide -Property Status -Column 1
to this:
$outputx = (Get-Service 'BFE').Status
It's a bit cleaner and a whole lot faster.
Cheers!
Jeffrey Snover[MSFT]
@jsnover
Distinguished Engineer and Lead Architect for Windows Server and System Center
Thanks Jeff, Cheers!
ReplyDelete