diff --git a/cfbs.json b/cfbs.json index 43cba02..21bbd61 100644 --- a/cfbs.json +++ b/cfbs.json @@ -135,6 +135,15 @@ "bundles inventory_unshadowed_users:main" ] }, + "inventory-windows-services": { + "description": "Inventory running Windows services.", + "subdirectory": "inventory", + "steps": [ + "copy inventory-windows-services.cf services/cfbs/inventory-windows-services/", + "policy_files services/cfbs/inventory-windows-services/", + "bundles inventory_windows_services_running" + ] + }, "library-for-promise-types-in-bash": { "description": "Library enabling promise types implemented in bash.", "subdirectory": "libraries/bash", diff --git a/inventory/inventory-windows-services.cf b/inventory/inventory-windows-services.cf new file mode 100644 index 0000000..ca7b25f --- /dev/null +++ b/inventory/inventory-windows-services.cf @@ -0,0 +1,28 @@ +bundle agent inventory_windows_services_running +# @brief Inventory Windows services that are running +# @inventory Windows services running +{ + vars: + windows:: + "_cache" string => "$(sys.statedir)/windows-services-running.json"; + + "_data" data => readjson("$(_cache)"); + "_indices" slist => getindices(_data); + + "i[$(_indices)]" + string => "$(_data[$(_indices)][DisplayName])", + meta => { "inventory", "attribute_name=Windows services running"}; + + + commands: + windows:: + "Get-Service | Where-Object {$_.Status -eq 'Running'} | ConvertTo-Json | Set-Content -Path '${_cache}'" + contain => powershell; + +} + +bundle agent __main__ +{ + methods: + "inventory_windows_services_running"; +}