Delete all users where userID = Null

-Andrew-
Kilo Sage

Hi all,

 

I recently included a field into our LDAP import, this has forced 42,000 records to be imported to the Sys_User table.

 

I need to remove these, i don't mind deleting all users and running a new import (this would be the better option).

 

Does anyone know how to do this?

 

Thanks,

Andrew

1 ACCEPTED SOLUTION

Slight modifications

Firstly id recommmend you do this in batches, lets say 10k at a time

 

function removeComputers() {
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery('user_name=null');

gs.setLimit(10000);

gr.setWorkflow(false);
gr.query();
var deleteCount = 0;
while(gr.next()){

gr.deleteRecord();
deleteCount++;
}
gs.print('Records Deleted: '+ deleteCount);
}

 

 

 

Also noticed something odd at the start of your script, make sure its not a copy paste error, you are calling a different function and the deletion function has s different name.

 

deleteSys_user();
function removeComputers() {
-Anurag

View solution in original post

12 REPLIES 12

Anurag Tripathi
Mega Patron
Mega Patron

Hi Andrew,

 

Both replies form Ankur and Abhishek are right, id just add gr.setWorkflow('false'); as well to improve the query performance.

 

-Anurag

-Anurag

-Andrew-
Kilo Sage

Thanks all - i messed around a bit and found the below; taking a v long time though.

deleteSys_user();
function removeComputers() {
 var gr = new GlideRecord("sys_user");
 gr.addEncodedQuery('user_name=null')
 gr.query();
 var deleteCount = 0;
 while(gr.next()){
gr.setWorkflow(false);
 gr.deleteRecord();
 deleteCount++;
 }
 gs.print('Records Deleted: '+ deleteCount);
}

Slight modifications

Firstly id recommmend you do this in batches, lets say 10k at a time

 

function removeComputers() {
var gr = new GlideRecord("sys_user");
gr.addEncodedQuery('user_name=null');

gs.setLimit(10000);

gr.setWorkflow(false);
gr.query();
var deleteCount = 0;
while(gr.next()){

gr.deleteRecord();
deleteCount++;
}
gs.print('Records Deleted: '+ deleteCount);
}

 

 

 

Also noticed something odd at the start of your script, make sure its not a copy paste error, you are calling a different function and the deletion function has s different name.

 

deleteSys_user();
function removeComputers() {
-Anurag

Thanks - this doesn't seem to be working for me 

Just noticed your ending sentence - that was a paste error - thanks though!!