Blog

Find Computers without Software

Find computers that don't have software installed with this script.  This helps find computers that are not properly being discovered for CI information.

Remember to run in a development instance and test before running in production ServiceNow instance.

1. Elevate your privilege to security_admin.
2. In the Left Navigator > Scripts - Background
3. Paste this in the Run Scripts area. 

//change the tablename if you want to query a different table like cmdb_ci_server
//add a parameter to the function call if you want to add a query
gs.print(getComputersWithoutSoftware('cmdb_ci_computer'));
function getComputersWithoutSoftware(compTableName, compQuery) {
  var computers = [];
  var grComputer = new GlideRecord(compTableName);
  grComputer.addEncodedQuery(compQuery);
  grComputer.query();
  while (grComputer.next()) {
    var grInstalledSoftware = new GlideRecord('cmdb_sam_sw_install');
    grInstalledSoftware.addQuery('installed_on', grComputer.sys_id);
    grInstalledSoftware.query();
    if (grInstalledSoftware.getRowCount() == 0) {
    computers.push(grComputer.name.toString());
  }
  }
  return computers;
}

4. Run Script