Printing text files and move them afterwards

Welcome Forums General PowerShell Q&A Printing text files and move them afterwards

This topic contains 2 replies, has 2 voices, and was last updated by

1 year, 8 months ago.

  • Author
  • #86840

    Topics: 8
    Replies: 10
    Points: 0
    Rank: Member

    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

    Topics: 8
    Replies: 10
    Points: 0
    Rank: Member

    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

    Topics: 2
    Replies: 999
    Points: 1,946
    Helping Hand
    Rank: Community Hero

    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


    [string]$Printer = "Brother MFC-J985DW Printer"

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

The topic ‘Printing text files and move them afterwards’ is closed to new replies.