Printing text files and move them afterwards

This topic contains 2 replies, has 2 voices, and was last updated by  postanote 1 week ago.

  • Author
    Posts
  • #86840

    Jaapie bakker
    Participant

    Hi Guys,

    For an old legacy system we need to print some files from an 2012 server every 10seconds or something. When that is done, i need to move them to another folder.

    I found and modified this script below, but when i run the script it does not print, but i move the files and then i get an notepad error that i cannot find the files to print.

    Could someone help me please?

    dir "C:\temp\Print\*.txt" |
    ForEach-Object {
    $moved = $False
    Start-Process -FilePath $_.FullName -Verb Print
    Do {
    Try {
    $_ |
    Move-Item -Destination "C:\temp\Printed" -ErrorAction Stop
    $moved = $True
    }
    Catch {
    $moved = $False
    Start-Sleep 1
    }
    } While (!$moved)
    }

  • #86842

    Jaapie bakker
    Participant

    When i put a start-sleep 5 between start-proces en Do { it works but i get an error message.

    Sleep-start : The term 'Sleep-start' is not recognized as the name of a cmdlet, function, script file, or operable program. C
    heck the spelling of the name, or if a path was included, verify that the path is correct and try again.
    At line:5 char:5
    + Sleep-start 5
    + ~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Sleep-start:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

  • #87097

    postanote
    Participant

    There is no such cmdlet called 'Sleep-start', hence your error.
    The snippet you posted shows the correct command.

    Start-Sleep 1

    So, I am not sure where this 'Sleep-start' is coming from.

    You also don't have a printer destination specified.

    For example —

    Function Start-PrintTestPage
    {
    [cmdletbinding()]

    [Alias('sptp')]

    Param
    (
    [string]$Printer = "Brother MFC-J985DW Printer"
    )

    Invoke-CimMethod -MethodName printtestpage `
    -InputObject (Get-CimInstance win32_printer -Filter "name LIKE '$printer'")
    }

You must be logged in to reply to this topic.