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 <a href="https://www.papercut.com/kb/Main/DeletingUsers" target="_blank" rel="noopener noreferrer">delete users</a> 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 <a href="https://www.python.org/" target="_blank" rel="noopener noreferrer">Python</a> or <a href="https://technet.microsoft.com/en-us/library/bb978526.aspx" target="_blank" rel="noopener noreferrer">PowerShell</a> 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.
<pre class="lang:python decode:true ">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)</pre>
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 <a href="https://www.papercut.com/products/ng/manual/common/topics/tools-web-services.html" target="_blank" rel="noopener noreferrer">PaperCut API's</a> currently available.
[widgetkit id="48"]

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.
<div class="well well-lg">
<h3 style="text-align: center;">Get in touch today | 01256 246970 | <a href="mailto:sales@selectec.com">sales@selectec.com</a></h3>
</div>
&nbsp;