
How it works...
In the first step of the recipe, you use the utility wevtutil.exe to tell the Spooler to start recording printer usage details to the event log. Printer usage event logging is not turned on by default, and at present, there is no PowerShell cmdlet to turn on event logging.
In the first sub-step in step 2, you create an advanced function by decorating the Param() block with the CmdletBinding() attribute. In the second sub-step, you get all the printer event log entries that relate to usage reporting (ObjectID 307). In the third sub-step in step 2, the function iterates through each entry in the log. In the fourth sub-step, for each entry, you create a hash table that holds the information returned from the event log. In sub-step 5 and sub-step 6, you create a PSObject for the event log entry and change the object type name from PSObject to Packt.PrintUsage. Finally, in sub-step 7, you also close out the foreach loop and the advanced function.
Finally, in step 3, you define an alias for this new function. Then you use the function, via its alias, and pipe the output objects to Format-Table to produce a nice output like this:
