Hello all, I am trying my hand at C# and at the same time build a
cmdlet for Powershell. I have read the sparse documentation on MSDN
regarding building your cmdlets and it leaves a lot to be desired (but
then again PS is new so I don't expect the docs to be all that
anyways).
What I am trying to do is build a cmdlet called Get-PrintJobs that
will take the arguments "servername" and "printserver" which will then
return all the printjobs in the queue for the specified printer. I
found in the .NET FW 3.0 there is System.Printing.PrintQueue ( and I
have tried PrintQueCollection) that has a method
"GetPrintJobInfoCollection" which if I'm correct returns all the info
on the jobs in a queue. I kept getting variations on the error below.
I get an error when I build it I get this warning
'System.Printing.PrintQueueCollection' is a 'type', which is not valid
in the given context
I think it something to do with type definitions but I'm unclear on
how to properly impliment it. Here is my code below. Any Suggestions
would be greatly appreciated from this newbie.
Norm
PS:: I used the PSCmdlet templet provided by David Aiken over at
Channel9
using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Collections;
namespace PSGetPrintjobs
{
[Cmdlet(VerbsCommon.Get, "PrintJobs", SupportsShouldProcess =
true)]
public class GetPrintJobs : PSCmdlet
{
#region Parameters
[Parameter(Position = 0,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enter the Servername")]
[ValidateNotNullOrEmpty]
public string servername
{
get { return servername;}
set {servername = value;}
}
[Parameter(Position = 1,
Mandatory = true,
ValueFromPipelineByPropertyName = true,
HelpMessage = "Enter the Printer name")]
[ValidateNotNullOrEmpty]
public string printername
{
get { return printername; }
set { printername = value; }
}
#endregion
protected override void ProcessRecord()
{
try
{
WriteObject(System.Printing.PrintQueue.GetPrintJobInfoCollection());
}
catch (Exception)
{
}
}
}
Quote:}