- 1 year ago
Error capturing number of document copies sent to printer using "Win32_PrintJob" Class
To capture the number of document copies sent to a printer using the Win32_PrintJob
class in PowerShell, you can use the Get-WmiObject
cmdlet along with the Win32_PrintJob
class. Here's an example:
powershell$printerName = "Printer Name"
# Get the print job for the specified printer
$printJob = Get-WmiObject -Class Win32_PrintJob | Where-Object { $_.Name -eq $printerName }
if ($printJob) {
$numCopies = $printJob.TotalPages
Write-Output "Number of Copies: $numCopies"
} else {
Write-Output "No print job found for printer: $printerName"
}
Replace "Printer Name"
with the name of the printer for which you want to capture the number of document copies. The script retrieves all print jobs using the Win32_PrintJob
class and filters them based on the printer name. If a print job is found, it retrieves the TotalPages
property, which represents the number of document copies sent to the printer.
Run the script in PowerShell, and it will output the number of copies for the specified printer. If no print job is found for the printer, it will display a message indicating that no print job was found.
Make sure to run the script with appropriate privileges to access the WMI information.