N
N
nfire2019-11-19 15:32:08
PowerShell
nfire, 2019-11-19 15:32:08

How to pass a value with "\\" characters to Get-Counter?

I am writing a script for accounting for printed pages:

$date = get-date -format dd-MM-yyyy
$printername = Get-Printer | select -expand Name
foreach ($printer in $printername) {
$number = Get-Counter "\Очередь печати($printer)\Всего напечатано страниц" | Foreach-Object {$_.CounterSamples[0].CookedValue}
Convertto-html -title "Статистика печати" -PreContent "Количество распечатанных листов на $printer за $date : <b>$number</b>" >> e:\counter_print_pages.html}

Everything works fine until it reaches the network printer:

Get-Counter : Invalid performance counter path \Print Queue(\\192.168.1.13\HP LaserJet P2035)\Total Pages Printed.
E:\pagecount.ps1:4 char:11
+ $number = Get-Counter "\Print Queue($printer)\Total Pages Printed ...
+ ~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (: ) [Get-Counter], Exception
+ FullyQualifiedErrorId : CounterPathIsInvalid,Microsoft.PowerShell.Commands.GetCounterCommand

Moreover, the output to the file works without errors (except for the number of pages, of course):

Number of sheets printed on Fax for 19-11-2019 : 0
Number of sheets printed on Adobe PDF for 19-11-2019 : 0
Number of sheets printed on \\192.168.1.13\HP LaserJet P2035 for 19-11-2019 :

Of course, you can take not Name, but DriverName, but then it is not clear that this is a network printer.
Actually a question - how to make processing for network printers with names on \\?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2019-11-19
@BeatHazard

I may be wrong, but the system does not have counters for printers connected not locally, but over the network. You can verify this by opening the Performance monitor and looking at the list of devices in the Print Queue category.
I think you need to upload information about the number of printed pages on the PC / server from which this printer is shared.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question