Get-PrintJob appending to existing CSV

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Richard Siddaway Richard Siddaway 3 years, 8 months ago.

  • Author
    Posts
  • #10779
    Profile photo of Jonas Andresen
    Jonas Andresen
    Participant

    Hi Powershell.org users

    I'm trying to get overview of the printqueue of a specific printer.

    I'm able to get what I need from the following command

    Get-PrintJob -PrinterName \\printserver\printer| select -Property ComputerName, DocumentName, Position, PrinterName, SubmittedTime, TotalPages, Username | Export-Csv c:\temp\printqueue.csv

    But I need a way of appending new jobs (and not adding perse and not adding a job that is already on it) to the csv file.

    How would I do this?

  • #10790
    Profile photo of Richard Siddaway
    Richard Siddaway
    Moderator

    If you are using PowerShell 3.0 or 4.0 then Export-csv gets an -Append parameter that will allow you to add records to a CSV file. The kicker is in your requirement to not add a job that already exists.

    I suspect that you'll need to read the CSV file into an array; get the current print jobs; add them to the array; select for unique jobs and export the CSV.

    From the list of properties you are selecting what are you going to use to uniquely identify a job?

You must be logged in to reply to this topic.