Lock Out Users in Sandbox Instances

Want to lock out users from using your ServiceNow Dev, Test, and Sandbox instances?  This script will lock out all the users that are not admins.  Afterwards you can unlock/lock the users you want to have access, and they won't accidentally login into the wrong instance.

Do not run in ServiceNow Production!  You'll lock out all your users!

How to run this script

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

function lockoutUsers() {
    var users = new GlideRecord("sys_user");
    gs.print("User query: " + users.getEncodedQuery() + " = " + users.getRowCount());
    while ( {
        users.locked_out = true;
  //Uncomment out the bottom line when you are ready to run this!
        gs.print(users.getDisplayValue() + " was disabled");

4. Run Script