Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 8583

Printing to TIFF Conversion then verifying file has printed.

$
0
0

Have a script:

Function Printfiles{
 param ($dirfiles, $log)
 foreach ($file in $dirfiles){
  #Printing each file in Blackice Dir
  $file | Out-Printer
 }
}

Function ValidatePrinted{
 param ($dirfiles, $Efile)
 $TiffDir = ""
 foreach ($file in $dirfiles){
  #Converting to string to change extension
  $extension = Get-ChildItem $file.Name | %{$_.Extension}
  $filest = [string]$file.name
  [string] $Vfile = $filest.replace($extension, ".tiff")
  #checking if file printed.
  if (Test-Path $TiffDir\$Vfile ){
    #File Printed
    "$Vfile exists" >> $log
   } Else {
    #File did not print
    "$Vfile does not exist" >> $log
    #adding to do not delete file
    $Vfile >> $Efile
    #Sending to Event Viewer
    Write-EventLog -LogName Application -Source BlackIcePrint -EventId 1000 -EntryType Error -Message "Did not convert $Vfile."
    #Emailing error
    EmailError $Vfile
   }
 }
}

My issue is that periodically when this runs it is hitting the validate routine and the files are still queued up and printing.  This is a file conversion versus physical printer. 

My thought was to modify this script to do something like this, but since I did not write the original script but inherited it I am at my learning curve trying to figure this out...but I think I would like to do something like this

Function PrintAndValidateFiles{
     foreach ($file in $dirfiles){
          $file | Out-Printer - Wait #I want it to wait here until file is printed before continue
          #Waits until file is printed(converted)
          $extension = Get-ChildItem $file.Name | %{$_.Extension}
          $filest = [string]$file.name
          [string] $Vfile = $filest.replace($extension, ".tiff")
          #Is File Printed?
         if (Test-Path $TiffDir\$Vfile ){
           #File Printed
           "$Vfile exists" >> $log
          } Else {
           #File did not print
           "$Vfile does not exist" >> $log
           #adding to do not delete file
           $Vfile >> $Efile
           #Sending to Event Viewer
          Write-EventLog -LogName Application -Source BlackIcePrint -EventId 1000 -EntryType Error -Message "Did not convert $Vfile."
          #Emailing error
          EmailError $Vfile
          }
     }
}

I believe it should all work correctly if I can just figure out the -Wait portion to make the script stop executing until after the printing is done then validate the TIFF file is there.

Any suggestions, pointers or help to a newbie would be greately appreciated.

Steven

 


Viewing all articles
Browse latest Browse all 8583

Trending Articles