Disabling All Schedules and Users with Command Manager

Today I’ll share two handy MicroStrategy Command Manager scripts I use quite often during upgrade testing.  When preparing for an upgrade, you’ll need to create a test copy of your metadata.  But  you may run into two problems:
  1. If you use Time Based schedules, they’re still active and could either email users or at least waste time processing during production schedules.  
  2. If you’re on a CPU license with a Named user test key, you’ll more than likely be out of compliance.

These two scripts are similar to each other, so I’ve included them in the same post after the jump.  Enjoy!


Disabling Schedules

If you use Event Based schedules, you’re probably safe since you more than likely aren’t connecting to your test box and firing them unless you intend to.  However, this script can also be useful if there is an ETL problem on any given day and you need to quickly halt subscriptions on a moments notice.
Quick Tip
If you’re using this script for a test instance, another quick tip I’ll throw out there is to also disable Email sending.  This will allow you to properly test the Schedules later without sending emails to users.  This can be done via Desktop by expanding the Administration -> Delivery Managers -> Transmitters and opening Email.  In the Message Output tab, you can uncheck “Send messages to recipients via SMTP”.  You’ll probably want to check “Save to File” and provide a path so that you can see the output of your tests.
If you right click a Schedule via Desktop, you’ll see that there isn’t an option to disable it.  The trick, however, is to simply set the Schedule’s Start Date to the future.  The Command Manager command to do this is:
ALTER SCHEDULE “ScheduleName” STARTDATE 12/20/2012;
If you’ve only got a few schedules, you may just want to type them out, save that script, and execute it when you need it.  But if you have a lot of schedules or feel like they’ll be changing often, you can do that dynamically with the following procedure:
ResultSet lSchedules = executeCapture(“LIST ALL SCHEDULES;”);
lSchedules.moveFirst();
while (!lSchedules.isEof())
{
printOut(“Disabling: ” +  (String)lSchedules.getFieldValueString(NAME));
execute(“ALTER SCHEDULE “” + (String)lSchedules.getFieldValueString(NAME)+ “” STARTDATE 12/20/2012;”);
            lSchedules.moveNext();
}
Once you want to turn them back on, just change that STARTDATE parameter to a date in the past.
Disabling Users
Generally when you have a CPU production license, you’ll have an accompanying Named User license with a fixed number of test accounts.  If you’ve just copied your production metadata for testing, you’re now out of compliance.  If you’ve got a CPU license, there’s a good chance you have thousands of user accounts and don’t want to sit there disabling them through User Manager.  Fortunately, there’s a script for that.  I’ll generally run this script which disables every account except Administrator (you actually get an error if you try to disable Administrator, but we’ll purposefully skip it anyway), and then go back and re-enable the test accounts we want to keep active afterwards.
ResultSet USERS = executeCapture(“LIST MEMBERS FOR USER GROUP “Everyone”;”);      //Put whatever group to query here
    USERS.moveFirst();
    while(!USERS.isEof()){
      ResultSet member=(ResultSet)USERS.getFieldValue(MEMBER_RESULTSET);     
      member.moveFirst();
      //go through each member in the group
      while(!member.isEof()){
          boolean isGroup = (Boolean)member.getFieldValue(IS_GROUP);
          /* verify it is not a group */
          if (!isGroup) {
            String USER = member.getFieldValueString(LOGIN);
            if (!USER.equals(“Administrator”)) {      //don’t modify the admin user, or it’ll give an error and crash the script
            EXECUTE(“ALTER USER “” + user + “” DISABLED;”);     //What you want to do to the user goes here
            }
          }
          member.moveNext();
      }
      USERS.moveNext();
    }
You could also use this script to disable all users of a particular group (just change the Everyone in the first line to whatever group name you want) or to change other properties of users (just change the DISABLED to a different property change).   Depending how many users you have in your system, this may take a while to run, but it’s definitely faster than doing it manually!

You may also like...