Set password policy for local accounts

prasad8
Giga Expert

Hi,

I have to set password reset policy for users having "AD user id" is empty and users who having "Admin" or "Security Admin" roles. 

"Ad user id" is field in user record. 

For archiving this, I have written scheduled job, Below the script.

Script:

var gr = new GlideRecord('sys_user');
gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');
gr.query();
while (gr.next()) {
gr.password_needs_reset = true;
gr.update();

 

Here i need to build query, Can any one help on this.

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery("u_ad_user_idIEEMPTY"); // use correct field name
gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');
gr.addEncodedQuery("roles=admin^ORroles=security_admin");
gr.query();
while (gr.next()) {
    gr.password_needs_reset = true;
    gr.update();
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

4 REPLIES 4

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

update as this

var gr = new GlideRecord('sys_user');
gr.addEncodedQuery("u_ad_user_idIEEMPTY"); // use correct field name
gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');
gr.addEncodedQuery("roles=admin^ORroles=security_admin");
gr.query();
while (gr.next()) {
    gr.password_needs_reset = true;
    gr.update();
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thanks for reply, 

I have added query for getting last password changed is 30 days is notworking, 

"gr.addQuery('u_password_last_changed', '>', 'gs.daysAgo(30))');"

As per my requirement if Last password changed date is greater then 30 days then only i need to make true "Password reset" field.

 

Currently it is working like every day it is updating the Password reset check box field

 

Help me on this .

 

Thanks,

Prasad.

 

then update the query as this

gr.addEncodedQuery("u_password_last_changedRELATIVELT@dayofweek@ago@30");

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@prasad

Hi Prasad,

I could see you marked my response as correct earlier and now it is not.

Any reason for that?

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader