Detect Windows Services


#1

Greetings Professionals,

Does chef has power to detect the services that are running on windows nodes ? for example i need to check on what are all the servers the W3svc services are running? is it possible through chef,- ohai supports this feature?

Please help

Thanks
Prash


#2

Chef is capable working with windows services per: https://docs.chef.io/resource_service.html


#3

If you just need to check if a process is running, knife and powershell will be your best bet

knife winrm name:web1 --winrm-user <foo>\\<bar> --winrm-shell powershell '[bool]$(Get-Process -Name w3wp -ErrorAction SilentlyContinue)' 

This returns true if w3wp is running, false if not


#4

Might I also suggest looking into Inspec to check the compliance of your servers with a pre-defined policy (like services)

https://www.inspec.io/docs/reference/resources/service/

Regards,
Dan-Joe


#5

If your node isn’t in the same network that your workstation, you can use the following ruby code within ruby_block or directly in the recipe:

status = powershell_out!('(Get-Service serviceName).Status')

or

status = ´powershell.exe (Get-Service serviceName).Status´

to catch the response of script.

I hope that it helps you !

Regards.


#6

Can you please elaborate im trying to check services running on one of my windows machine 10.0.x.x.x and password *****
correct me if im wrong is this the way to execute the command?

knife winrm name:web1 --winrm-user 10.0.x.x.x*****; --winrm-shell powershell '[bool]$(Get-Process -Name w3wp -ErrorAction SilentlyContinue


#7

Run knife from your workstation where you have knife installed

There should be no semicolon ‘;’ and you are missing a trailing ‘)’