img

Delete Inactive PaperCut Users


Time to share one of our secret PaperCut scripts – How to Delete Inactive PaperCut Users (do not tell our PS team!)

From time to time end users may find it useful to purge inactive users from their PaperCut install. Inactive users are using a user license, and that may have a knock-on impact if the license count is exceeded.

We all know PaperCut can delete users that do not exist in the sync source, but as of v17.0.5, there is no “out of the box” method to remove inactive users from the PaperCut database.

The script will use Python or PowerShell and you can easily schedule these using any scheduling tool such as the built-in Windows scheduler for tasks.

The thinking here is, if a user has never used the system, they qualify as inactive and can happily be removed. With on-demand user creation enabled they can always be added again when/if they ever print.

The downside to this method is… just because a user has zero as a page count does not mean they are not using the system. Another issue is, perhaps they have just been added to the system as a new user. If you run the script after a nightly sync, they may not have had a chance to have any activity.

import xmlrpclib
 
host_name = 'papercut'
port = 9191
auth_token = 'CorrectHorseBatteryStaple'
test = True # Set this to False if you actually want to remove the users
 
server = xmlrpclib.Server('http://%s:%d/rpc/api/xmlrpc' % (host_name, port))
 
users = server.api.listUserAccounts(auth_token, 0, 1000)
 
if test:
    print "This action would delete the users below"
 
for user in users:
    if server.api.getUserProperty(auth_token, user, "print-stats.job-count") == "0":
        if test:
            print user
        else:
            server.api.deleteExistingUser(auth_token, user)

In an ideal world, we would be able to set a time frame for inactivity, for example, no activity in the last 60-90 days. Sadly at present, there is no way to get the last activity from the PaperCut API’s currently available.

  • Click to see a list of all the API options:

    propertyName - The name of the property to get. The following list of property names can also be set using #setUserProperty:
    balance: the user's balance, unformatted, e.g. "1234.56".
    primary-card-number
    secondary-card-number
    card-pin
    department
    disabled-net: true if the user's 'net access is disabled, otherwise false
    disabled-print: true if the user's printing is disabled, otherwise false
    email
    full-name
    internal: true if this is an internal user, otherwise false
    notes
    office
    print-stats.job-count: total number of print jobs from this user, unformatted, e.g. "1234"
    print-stats.page-count: total number of pages printed by this user, unformatted, e.g. "1234"
    net-stats.data-mb: total 'net MB used by this user, unformatted, e.g. "1234.56"
    net-stats.time-hours: total 'net hours used by this user, unformatted, e.g. "1234.56"
    restricted: true if this user's printing is restricted, false if they are unrestricted.
    home: the user's home folder (a double-quoted UNC path)
    username-alias: The alias for a given user
    unauthenticated: true if the user is an unauthenticated user, {otherwise false
    dont-hold-jobs-in-release-station: true if the user's jobs will bypass all release station queues, otherwise false
    dont-apply-printer-filter-rules: true if the user's jobs will bypass printer filter settings, otherwise false
    printer-cost-adjustment-rate-percent: The percentage modifier for the user's job costs, unformatted, e.g. "123.45". If the flag to enable adjustment is not set, returns -1
    dont-archive: true if the user's jobs will not be archived, false otherwise.
    auto-release-jobs: true if the user's jobs will always release on device login, otherwise false
    The following options are "read only", i.e. cannot be set using #setUserProperty:
    account-selection.mode: the user's account selection mode. One of the following:
    AUTO_CHARGE_TO_PERSONAL_ACCOUNT
    CHARGE_TO_PERSONAL_ACCOUNT_WITH_CONFIRMATION
    AUTO_CHARGE_TO_SHARED
    SHOW_ACCOUNT_SELECTION_POPUP
    SHOW_ADVANCED_ACCOUNT_SELECTION_POPUP
    SHOW_MANAGER_MODE_POPUP
    account-selection.can-charge-personal: true if the user's account selection settings allow them to charge jobs to their personal account, otherwise false.
    account-selection.can-charge-shared-from-list: true if the user's account selection settings allow them to select a shared account to charge from a list of shared accounts, otherwise false.
    account-selection.can-charge-shared-by-pin: true if the user's account selection settings allow them to charge a shared account by PIN or code, otherwise false.
    other-emails: user's other emails.

We considered trying to be clever and check the balance when the script runs and compare it to a previous value (the thinking here is if balance changed then they are active).
This is certainly possible but would involve storing the values somewhere.
PaperCut is very intelligent (you already knew that) and can store page count for scripts (for example, some scripts can count colour pages per day etc.) if we could use this data we might be on to something – sadly those options are not yet available via the API. The script above is as good as it get’s until we come up with a better idea.

And as a little bonus the script provides a list of users it will delete, what more could you want?

If you have a requirement or simply have some questions then get in touch with your Account Manager.

Get in touch today | sales@selectec.com

 

Latest News from Max McKean
img

PaperCut MF Version 17.3

The clever (and productive) PaperCut Dev team have been working tirelessly and ...

Written by: Max McKean

More
img

PaperCut MF Version 17.1

May is here, and summer is knocking at our doors. To distract us from BBQ's in ...

Written by: Max McKean

More

img

We have worked with Selectec for over 5 years. With their support we have been able to satisfy our direct and indirect clients with an extremely quick turnaround time in the supply of software. Their customer service is outstanding. The personal touch they offer, their flexibility and quick reaction time, comforts us in knowing that if things were to go wrong, the support is always there.

John Sweeney, Head of Product & Solutions Support Group Toshiba UK
Back to Top ↑