Search code examples
windowspowershellscriptingwindows-scripting

How to 'only' get the service 'status' in Windows? (alternative for `systemctl is-active service`)


I have been exploring on a windows alternative for following Linux command:

systemctl is-active firewalld

This command only gives us the strings active or inactive as output. So that it becomes helpful in developing various scripts.

I am so far unable to find such command for windows. Could you please help?


Solution

  • Powershell:

    $serviceName = "firewalld"
    (get-service $serviceName).status
    

    Will return Running/Stopped/Deactivated if a service with the name "firewalld" exists.