Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Last active May 10, 2024 20:01
Show Gist options
  • Save cmcdevitt/deeac2c4eb4fec37fb9d6bf7b3d34fce to your computer and use it in GitHub Desktop.
Save cmcdevitt/deeac2c4eb4fec37fb9d6bf7b3d34fce to your computer and use it in GitHub Desktop.
Delete Discovered Items that are not associated with a Vulnerable Item
/*
Use this instead:
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1349923
I quickely built this then notices the KB... sight...
This will need to be a FIX Script that will need to be run in the background
*/
var delete_count = 0;
var count = 0;
var table = 'sn_sec_cmn_src_ci';
var di = new sn_vul.PagedGlideRecord(table);
di.setSortField("sys_id");
while(di.next()){
var vi = new GlideRecord('sn_vul_vulnerable_item');
vi.addEncodedQuery('src_ci=' + di.gr.sys_id);
vi.query();
if(!vi.next()){
/*
#1:
A quick test to show you a single DI that it would delete
Comment out these for lines when done testing
Test: Run it and have it spit-out a DI Number. Verify the DI does not exist on the VIT table.
Look I did not have time for a more thural test!
*/
gs.info("Deleting " + di.gr.number);
if(delete_count = 1){
break;
}
delete_count++;
// #2: Uncomment me after testing!
//di.gr.deleteRecord();
}
count++;
}
gs.info("Deleted " + delete_count + " Discovered Items!");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment