I’ve been playing with get-printjob and am confused about using a positional parameter.
You can see a printer’s print job by typing “get-printjob” followed by either the printer’s name (a string) or a printer object (probably something like “$p,” assuming that I’ve done something like $p=get-printer… or the like.Â I understand the two parameter sets (in one, “1” means “-printername,” in the other, “1” means "-printerobject."Â But here’s what’s hanging me up.
If I have a printer named “Epson MX80” and I just type
get-printjob “Epson MX80”
Then I get “A parameter cannot be found that matches parameter name ‘name’.”
Now, if I type
get-printjob “-printername Epson MX80”
Then all is well.Â Furthermore, if I type print-job followed by the names of any drivers that I’ve got loaded but that have no actual printers associated with them, all’s well.
It looks to me as if the problem with typing get-printjob followed by a string is somehow confusing the PowerShell parser.Â I’d think that if I pass get-printjob a simple string then I GET that PoSH has to figure out if I’m asking for the -printername parameter set or the -printobject parameter set, but honestly that seems like a pretty easy question, no?
So my question is… I’ve got a cmdlet with two parameter sets.Â There is a positional parameter “1” that, once understood, kicks it into the first or second parameter set.Â It’s getting confused.Â Is there some way to help it, like
get-printjob [string]:“Epson MX80”
(I know, that syntax doesn’t exist) or something like that?