Advertisement
Guest User

printscript

a guest
Jul 15th, 2025
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  #Setup for logging#
  2. $hostname = hostname
  3. $datetime = Get-Date -f 'yyyyMMddHHmmss'
  4. $LogPath = "C:\temp"
  5. $logName = "InternalPrint-${env:USERNAME}-${hostname}-${datetime}.txt"
  6. $transcriptFile = Join-Path -Path $LogPath -ChildPath $logName
  7.  
  8. #GhostScript bin folder
  9. $ghBin = "C:\Program Files\gs\bin"
  10.  
  11. #Define Printer to use
  12. #$printer = "B5052COLOR" #Test
  13. $printer = "b3070color" #Prod
  14. #$printer = "B3063COLOR" #Backup Prod
  15.  
  16. #Create log path if not found
  17. if (-Not (Test-Path "${LogPath}")) {
  18.     write-host "${LogPath} not found, creating."
  19.     New-Item -ItemType directory -Path "${LogPath}"
  20. }
  21.  
  22. Start-Transcript -Path $transcriptFile | Out-Null
  23. write-host "`n`n`n"
  24. write-host "Beginning Communications_Internal_Print.ps1 ... `n`n"
  25.  
  26. # Set the Internal Print directory path
  27. $intPrintDir = "R:\REDACTED\Files\Correspondence\Printing"
  28.  
  29. $allFiles = Get-ChildItem -Path $intPrintDir\*\Internal\*.pdf
  30.  
  31. write-host "Sending files to printer ${printer}:`n"
  32. if ($allFiles.Count -gt 0) {
  33.     #update env variable PATH to include GhostScript bin if files found
  34.     $env:PATH = $env:PATH + ';' + $ghBin
  35.    
  36.     $newFile = ""
  37.     Foreach ($file in $allFiles) {
  38.         #Create Sent dir to move files to
  39.         if (-Not (Test-Path "$(Split-Path -Parent $file)\Sent")) {
  40.             New-Item -ItemType directory -Path "$(Split-Path -Parent $file)\Sent" | Out-Null
  41.         }
  42.    
  43.         $newFile = "$(Split-Path -Parent $file)\Sent\$(Split-Path -Leaf $file)"
  44.        
  45.         #Place a copy in Correspondence\Archive\Printing\MMDDYYYY\Internal\Sent for permanent archival
  46.         $archiveFile = "$(Split-Path -Parent $file)\Sent\$(Split-Path -Leaf $file)"
  47.         $archiveFile = $archiveFile.Substring(0, $newFile.IndexOf("Printing\")) + "Archive\" + $archiveFile.Substring($newFile.IndexOf("Printing\"))
  48.         #Create Archive dir if it doesn't exist and copy file
  49.         if (-Not (Test-Path "$(Split-Path -Parent $archiveFile)")) {
  50.             New-Item -ItemType directory -Path "$(Split-Path -Parent $archiveFile)" | Out-Null
  51.         }
  52.         Copy-Item $file -Destination $archiveFile
  53.  
  54.         #Print and move original file to inside Sent folder, will be kept for 30 days per Redwood job
  55.         #Send to printer
  56.         #REDACTED requested to print single sided. Command below is duplex for future reference.
  57.         #gswin64c.exe  -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -dFitPage -dPSFitPage -dFIXEDMEDIA -sPAPERSIZE=a4 -dDuplex -dTumble=true -sColorConversionStrategy=Gray -sDEVICE=mswinpr2 -sOutputFile="%printer%${printer}" "$file"
  58.         gswin64c.exe  -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -dFitPage -dPSFitPage -dFIXEDMEDIA -sPAPERSIZE=a4 -sColorConversionStrategy=Gray -sDEVICE=mswinpr2 -sOutputFile="%printer%${printer}" "$file"
  59.         Start-Sleep -Seconds 1
  60.  
  61.         #Test if file exists already first. Cannot move if already exists.
  62.         if (Test-Path "${newFile}") {
  63.             Move-Item -Path $newFile -Destination "${newFile}.${datetime}"
  64.         }
  65.         Move-Item -Path $file -Destination $newFile
  66.        
  67.         Write-Host "    " $newFile.Substring($newFile.IndexOf("Files\"))
  68.     }
  69.     write-host "`n"
  70. } else {
  71.     write-host "     No Internal files found to print. `n"
  72. }
  73.  
  74. write-host "Uploaded File Count: " $allFiles.Count
  75.  
  76.  
  77. write-host "`n`n`n"
  78. Stop-Transcript | Out-Null
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement