Windows Vista Forums

Printing Single Line From Powershell
  1. #1


    NuttyBee Guest

    Printing Single Line From Powershell

    I’d like to have Powershell print a single line to a dot matrix
    printer on a parallel port.

    Something like this:

    10/03/08 <20 spaces> 09:02:01 <20 Spaces> Users: 1<return>
    10/03/08 <20 spaces> 09:05:01 <20 Spaces> Users: 2<return>
    10/03/08 <20 spaces> 09:08:01 <20 Spaces> Users: 3<return>
    10/03/08 <20 spaces> 09:11:01 <20 Spaces> Users: 1<return>



    Every 3 minutes, I’d query the computer and spit out another line to
    the dot matrix printer in a Courier type font.

    How do I go about formatting and sending the result line by line to
    the dot matrix printer?

      My System SpecsSystem Spec

  2. #2


    RickB Guest

    Re: Printing Single Line From Powershell

    On Oct 13, 10:43*pm, Nutty...@xxxxxx wrote:

    > I’d like to have Powershell print a single line to a dot matrix
    > printer on a parallel port.
    >
    > Something like this:
    >
    > 10/03/08 * * *<20 spaces> * 09:02:01 <20 Spaces> *Users: 1<return>
    > 10/03/08 * * *<20 spaces> * 09:05:01 <20 Spaces> *Users: 2<return>
    > 10/03/08 * * *<20 spaces> * 09:08:01 <20 Spaces> *Users: 3<return>
    > 10/03/08 * * *<20 spaces> * 09:11:01 <20 Spaces> *Users: 1<return>
    >
    > Every 3 minutes, I’d query the computer and spit out another line to
    > the dot matrix printer in a Courier type font.
    >
    > How do I go about formatting and sending the result line by line to
    > the dot matrix printer?

    "{0:dd/MM/yyyy} <20 spaces> {0:hh:mm:ss} <20 Spaces> Users:
    {1:0}`n" -f
    [datetime]::now,$users|out-printer <prn name>

      My System SpecsSystem Spec

  3. #3


    Shay Levy [MVP] Guest

    Re: Printing Single Line From Powershell

    Hi NuttyBee@xxxxxx,

    Adding to Rick's string formmating, you can integrate the spaces, in the
    form of padding, into the format pattern. Negative values pads the string
    with spaces to the right side and positive valyues to the left. In the following
    format pattern, dd/MM/yyyy is 10 characters long, so add 20 to it and you'll
    end up with 30. Now, negate the value (-30) to pad spaces to the right side
    of the string. Do the same math for the second format pattern (-28):

    "{0,-30:dd/MM/yyyy}{0,-28:hh:mm:ss}Users:{1:0}`n" -f (get-date),$users


    ---
    Shay Levy
    Windows PowerShell MVP
    http://blogs.microsoft.co.il/blogs/ScriptFanatic
    PowerShell Toolbar: http://tinyurl.com/PSToolbar



    > I’d like to have Powershell print a single line to a dot matrix
    > printer on a parallel port.
    >
    > Something like this:
    >
    > 10/03/08 <20 spaces> 09:02:01 <20 Spaces> Users: 1<return>
    > 10/03/08 <20 spaces> 09:05:01 <20 Spaces> Users: 2<return>
    > 10/03/08 <20 spaces> 09:08:01 <20 Spaces> Users: 3<return>
    > 10/03/08 <20 spaces> 09:11:01 <20 Spaces> Users: 1<return>
    >
    > Every 3 minutes, I’d query the computer and spit out another line to
    > the dot matrix printer in a Courier type font.
    >
    > How do I go about formatting and sending the result line by line to
    > the dot matrix printer?
    >


      My System SpecsSystem Spec

  4. #4


    NuttyBee Guest

    Re: Printing Single Line From Powershell

    Thanks for the help. Out-Printer is perfect, except that at the end
    of every line, it ejects the page.

    Is there a way to just make it CR, but not eject the page?

    On Oct 17, 9:17*am, Shay Levy [MVP] <n...@xxxxxx> wrote:

    > Hi Nutty...@xxxxxx,
    >
    > Adding to Rick's string formmating, you can integrate the spaces, in the
    > form of padding, into the format pattern. Negative values pads the string
    > with spaces to the right side and positive valyues to the left. In the following
    > format pattern, dd/MM/yyyy is 10 characters long, so add 20 to it and you'll
    > end up with 30. Now, negate the value (-30) to pad spaces to the right side
    > of the string. Do the same math for the second format pattern (-28):
    >
    > "{0,-30:dd/MM/yyyy}{0,-28:hh:mm:ss}Users:{1:0}`n" -f (get-date),$users
    >
    > ---
    > Shay Levy
    > Windows PowerShell MVPhttp://blogs.microsoft.co.il/blogs/ScriptFanatic
    > PowerShell Toolbar:http://tinyurl.com/PSToolbar
    >
    >
    >

    > > I’d like to have Powershell print a single line to a dot matrix
    > > printer on a parallel port.
    >

    > > Something like this:
    >

    > > 10/03/08 * * *<20 spaces> * 09:02:01 <20 Spaces> *Users: 1<return>
    > > 10/03/08 * * *<20 spaces> * 09:05:01 <20 Spaces> *Users: 2<return>
    > > 10/03/08 * * *<20 spaces> * 09:08:01 <20 Spaces> *Users: 3<return>
    > > 10/03/08 * * *<20 spaces> * 09:11:01 <20 Spaces> *Users: 1<return>
    >

    > > Every 3 minutes, I’d query the computer and spit out another line to
    > > the dot matrix printer in a Courier type font.
    >

    > > How do I go about formatting and sending the result line by line to
    > > the dot matrix printer?- Hide quoted text -
    >
    > - Show quoted text -

      My System SpecsSystem Spec

  5. #5


    Shay Levy [MVP] Guest

    Re: Printing Single Line From Powershell


    I don't have a dot matrix printer to test against.
    As far as I know, each call to out-printer prints a page so try (id you can)
    to acumulate your output and print it in one piece.


    ---
    Shay Levy
    Windows PowerShell MVP
    http://blogs.microsoft.co.il/blogs/ScriptFanatic
    PowerShell Toolbar: http://tinyurl.com/PSToolbar


    > Thanks for the help. Out-Printer is perfect, except that at the end
    > of every line, it ejects the page.
    >
    > Is there a way to just make it CR, but not eject the page?
    >
    > On Oct 17, 9:17 am, Shay Levy [MVP] <n...@xxxxxx> wrote:
    >

    >> Hi Nutty...@xxxxxx,
    >>
    >> Adding to Rick's string formmating, you can integrate the spaces, in
    >> the
    >> form of padding, into the format pattern. Negative values pads the
    >> string
    >> with spaces to the right side and positive valyues to the left. In
    >> the following
    >> format pattern, dd/MM/yyyy is 10 characters long, so add 20 to it and
    >> you'll
    >> end up with 30. Now, negate the value (-30) to pad spaces to the
    >> right side
    >> of the string. Do the same math for the second format pattern (-28):
    >> "{0,-30:dd/MM/yyyy}{0,-28:hh:mm:ss}Users:{1:0}`n" -f
    >> (get-date),$users
    >>
    >> ---
    >> Shay Levy
    >> Windows PowerShell
    >> MVPhttp://blogs.microsoft.co.il/blogs/ScriptFanatic
    >> PowerShell Toolbar:http://tinyurl.com/PSToolbar

    >>> I’d like to have Powershell print a single line to a dot matrix
    >>> printer on a parallel port.
    >>>
    >>> Something like this:
    >>>
    >>> 10/03/08 <20 spaces> 09:02:01 <20 Spaces> Users: 1<return>
    >>> 10/03/08 <20 spaces> 09:05:01 <20 Spaces> Users: 2<return>
    >>> 10/03/08 <20 spaces> 09:08:01 <20 Spaces> Users: 3<return>
    >>> 10/03/08 <20 spaces> 09:11:01 <20 Spaces> Users: 1<return>
    >>>
    >>> Every 3 minutes, I’d query the computer and spit out another line to
    >>> the dot matrix printer in a Courier type font.
    >>>
    >>> How do I go about formatting and sending the result line by line to
    >>> the dot matrix printer?- Hide quoted text -
    >>>
    >> - Show quoted text -
    >>


      My System SpecsSystem Spec

Printing Single Line From Powershell problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Solved Single verticalblue line on screen nostaw5 General Discussion 2 16 Mar 2010
Output XML to Single Line Log File using VBScript Craig VB Script 0 19 May 2009
output group membership on a single line Steven PowerShell 4 27 May 2008
taskbar wont shrink to single line, always double Marty Vista General 3 07 Apr 2008
New powershell Analyzer with Suspendshell and Single Line "Immediate Mode" klumsy@xtra.co.nz PowerShell 0 11 Sep 2006