Well, I had a few use cases come up for this, so I decided to take another crack at it. I think this is going to work out better for us than my first version:
hostname=hostProps.get("system.hostname")
my_query="Select Name, DisplayName, PathName from Win32_Service"
def session = WMI.open(hostname);
import com.santaba.agent.groovyapi.win32.WMI
def result = session.queryAll("CIMv2", my_query, 15);
def exclude = ['ALG', 'AppVClient', 'COMSysApp','diagnosticshub.standardcollector.service',
'FontCache3.0.0.0', 'EFS', 'KeyIso', 'msiserver', 'MSDTC', 'Netlogon', 'NetTcpPortSharing',
'RpcLocator', 'RSoPProv', 'PerfHost', 'SamSs', 'SensorDataService', 'Spooler', 'sppsvc', 'TrustedInstaller',
'UI0Detect', 'UevAgentService', 'VaultSvc', 'vds', 'VSS', 'WdNisSvc', 'WinDefend', 'wmiApSrv',
'WRSVC', 'WSearch']
result.each(){
if ((!(it.PATHNAME.toLowerCase() ==~ /c:\\windows\\system32\\svchost\.exe .*/)) &&
(!(it.NAME in exclude))) {
println "WinService." + it.NAME.replaceAll(' ', '') + "=" + it.DISPLAYNAME
}
}
return 0;
Someone try this one and let me know if I missed anything obvious. I tried to cut out all the noise so it would only spit out the services anyone really cares about.