Exemple #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            string printServer      = null;
            string printerName      = null;
            string printerDisabled  = null;
            string printerJobCount  = null;
            string printerPageCount = null;
            string printerCostModel = null;

            foreach (string pcutPrinter in pcutPrinters)
            {
                try
                {
                    if (!(pcutPrinter.Substring(0, 2) == "!!"))
                    {
                        string[] pcutResult = pcutPrinter.Split('\\');
                        printServer      = pcutResult[0];
                        printerName      = pcutResult[1];
                        printerDisabled  = _serverProxy.GetPrinterProperty(printServer, printerName, "disabled");
                        printerJobCount  = _serverProxy.GetPrinterProperty(printServer, printerName, "print-stats.job-count");
                        printerPageCount = _serverProxy.GetPrinterProperty(printServer, printerName, "print-stats.page-count");
                        printerCostModel = _serverProxy.GetPrinterProperty(printServer, printerName, "cost-model");

                        PSObject thisPrinter = new PSObject();
                        thisPrinter.Properties.Add(new PSNoteProperty("Name", printerName));
                        thisPrinter.Properties.Add(new PSNoteProperty("Server", printServer));
                        thisPrinter.Properties.Add(new PSNoteProperty("Disabled", Convert.ToBoolean(printerDisabled)));
                        thisPrinter.Properties.Add(new PSNoteProperty("JobCount", Convert.ToInt32(printerJobCount)));
                        thisPrinter.Properties.Add(new PSNoteProperty("PageCount", Convert.ToInt32(printerPageCount)));
                        thisPrinter.Properties.Add(new PSNoteProperty("CostModel", printerCostModel));
                        WriteObject(thisPrinter);
                    }
                }
                catch (XmlRpcFaultException fex)
                {
                    ErrorRecord errRecord = new ErrorRecord(new Exception(fex.Message, fex.InnerException), fex.FaultString, new ErrorCategory(), fex);
                    WriteError(errRecord);
                }
                catch (Exception ex)
                {
                    ErrorRecord errRecord = new ErrorRecord(new Exception(ex.Message, ex.InnerException), ex.HResult.ToString(), new ErrorCategory(), ex);
                }
            }
        }