Powershell command to check number of jobs in print queue

Hi Team,

I need to check number of jobs in print queue in a printer using PowerShell script ?

Get the printer object for the printer named “My Printer”

$printer = Get-Printer -Name “My Printer”

Get a list of print jobs for the printer

$printJobs = Get-PrintJob -PrinterName $printer.Name

Count the number of print jobs in the queue

$jobCount = $printJobs.Count

Print the number of jobs in the queue

Write-Output “There are currently $jobCount jobs in the print queue for $($printer.Name).”