Administering PaperCut with PowerShell

PaperCut has a number of solutions for configuring PaperCut using scripts or programs. These include using the server-command tool on the PaperCut Application Server, or using the web services API from a number of programming languages such as C#, Java and more.

It is also possible to configure PaperCut from Windows PowerShell using the web services API, which brings a number of benefits, and this article explains how to get the best performance AND remote access by building a web services library to use in PowerShell.


PaperCut ships with a ServerCommandProxy class for C#, which presents most available API calls as methods of a class called PaperCUt.ServerCommand. This class can be compiled into a library and imported into PowerShell. The following notes should help you in your development environment:

  1. Make sure you have the .NET SDK installed (we tested with version 5. .NET Core 3.1 also works)
  2. Make sure you have access to an installation of PaperCut MF/NG. You can download PaperCut NG from the website. The C# code is identical for NG and MF.
  3. Use .NET Core SDK tools to create a new Project of type Class Library
    dotnet new classlib --name ServerCommandProxy
  4. Make the new project directory the current directory
    cd ServerCommandProxy
  5. Remove the default Class1.cs file that will have been added to the project.
    Remove-Item Class1.cs
  6. Copy the PaperCut supplied server proxy source code file into your project
    Copy-Item 'C:\Program Files\PaperCut MF\server\examples\webservices\csharp\ServerCommandProxy.cs'
  7. Add the third party XML-RPC .NET Core lib with the command
    dotnet add package Kveer.XmlRPC --version 1.1.1
  8. Build the library with
    dotnet build --configuration Release
  9. Import the installed Kveer library into the Powershell environment. For example:
    Add-Type -Path "$env:USERPROFILE\.nuget\packages\kveer.xmlrpc\1.1.1\lib\netstandard2.0\Kveer.XmlRPC.dll"
  10. Import the new ServerCommandProxy library you have just built into the Powershell environment. For example:
    Add-Type -Path "$PWD\bin\Release\net5.0\ServerCommandProxy.dll"
  11. Create a new instance of the ServerCommandProxy class
    $s = New-Object PaperCut.ServerCommandProxy("localhost",9191,"token")
    1. Make sure you have configured the auth token in PaperCut MF/NG by editing the advanced config key auth.webservices.auth-token
    2. In versions of PaperCut prior to version 19.2.3 use $s = New-Object ServerCommandProxy("localhost",9191,"token")
  12. Finally, make your first call against the PaperCut server programmatically

Here is another more complex, if slightly crude, example that deletes all internal users. Note: Needs PaperCut MF/NG 19.2.3 or above

$s.GetGroupMembers("!!Internal Users!!", 0, 10000) |
>>  foreach {$s.DeleteExistingUser($_)}

That’s it! You’re now able to make calls to the PaperCut Application Server via the web services API. More tips on using the.API here.

Categories: How-to Articles, Scripting and APIs

Keywords: PaperCut, PowerShell