PaperCut has a number of supported methods for configuring PaperCut programmatically. These include using the server-command tool from the PaperCut Application Server, or calling this tool from remote machines. PaperCut can also be called programmatically via our APIs from a number of programming languages such as C#, Java and more.
It is also possible to configure PaperCut from PowerShell. PowerShell allows for the import of libraries into the PowerShell environment to extend its capabilities. Administrators can then take advantage of the advanced features of PowerShell (when compared to the traditional command line) including the easy maintenance of scripts.
PaperCut already ships with a ServerCommandProxy class for C#, which presents all available API calls as methods of a class. This class can be compiled as a library with relative ease, and imported into PowerShell for usage;
- Use Visual Studio to create a new Project of type Class Library with the name of ServerCommandProxy.
- Remove the default Class1.cs Visual Studio will have added to the project.
- Choose Add Existing Item and navigate to
and add the ServerCommandProxy.cs file to the project
- Double click this file/class and wrap everything after the using
CookComputing.XmlRpc line in a namespace called PaperCut
- Add a reference to the CookComputing.XmlRpcV2.dll library to the project. If you don’t have these libraries, you will need to download these from the XML-RPC website, found here:
You’ll need to use something other than the Windows unzip method to find the libraries within, as they live in a folder the Windows archive tool doesn’t acknowledge.
- Compile the project to create your ServerCommandProxy.dll
From PowerShell, it’s now simply a case of importing these libraries to start configuring PaperCut from the shell.
- First, create a variable that saves the path the ServerCommandProxy.dll and CookComputing.XmlRpcV2.dll files live in. In my example this is;
$libPath = C:\VS\ServerCommandProxy\bin\Debug
- Then, import the libraries into the environment;
Add-Type -Path “$libPath\ServerCommandProxy.dll”
Add-Type -Path “$libPath\CookComputing.XmlRpcV2.dll”
- Create a new instance of the ServerCommandProxy class;
$s = New-Object PaperCut.ServerCommandProxy(“localhost”,9191,”password”);
- Finally, make your first call against the PaperCut server programmatically;
That’s it! You’re now able to make all valid calls against the PaperCut Application Server via the supported API set.
Categories: Scripting, Tips & Tricks, Configuration , Administration
Keywords: PaperCut, PowerShell