Display Name in windows_service resource?

Hello All,

Is there a way to use the display name in windows_service resource? I am trying to stop and disable a bunch of services but I get error that the windows service was not found or is not installed. But the problem is that I am referring to the services with their Display Names and will have to change all the names to Service Name if display names are not supported.

Thanks

You can probably get the actual service names from PowerShell. I’m not sure where your display names are stored, but if they are in an array or something then maybe the following would work:

["Background Intelligent Transfer Service", "Windows Time"].each do |display_name|
  service_name = powershell_out("(Get-Service | Where DisplayName -eq '#{display_name}').Name").stdout
  windows_service service_name
end

Gist is using powershell_out to pull it from PowerShell. I think there is a win32-service ruby gem as well but I haven’t personally used it.

1 Like