Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Setup for logging#
- $hostname = hostname
- $datetime = Get-Date -f 'yyyyMMddHHmmss'
- $LogPath = "C:\temp"
- $logName = "InternalPrint-${env:USERNAME}-${hostname}-${datetime}.txt"
- $transcriptFile = Join-Path -Path $LogPath -ChildPath $logName
- #GhostScript bin folder
- $ghBin = "C:\Program Files\gs\bin"
- #Define Printer to use
- #$printer = "B5052COLOR" #Test
- $printer = "b3070color" #Prod
- #$printer = "B3063COLOR" #Backup Prod
- #Create log path if not found
- if (-Not (Test-Path "${LogPath}")) {
- write-host "${LogPath} not found, creating."
- New-Item -ItemType directory -Path "${LogPath}"
- }
- Start-Transcript -Path $transcriptFile | Out-Null
- write-host "`n`n`n"
- write-host "Beginning Communications_Internal_Print.ps1 ... `n`n"
- # Set the Internal Print directory path
- $intPrintDir = "R:\REDACTED\Files\Correspondence\Printing"
- $allFiles = Get-ChildItem -Path $intPrintDir\*\Internal\*.pdf
- write-host "Sending files to printer ${printer}:`n"
- if ($allFiles.Count -gt 0) {
- #update env variable PATH to include GhostScript bin if files found
- $env:PATH = $env:PATH + ';' + $ghBin
- $newFile = ""
- Foreach ($file in $allFiles) {
- #Create Sent dir to move files to
- if (-Not (Test-Path "$(Split-Path -Parent $file)\Sent")) {
- New-Item -ItemType directory -Path "$(Split-Path -Parent $file)\Sent" | Out-Null
- }
- $newFile = "$(Split-Path -Parent $file)\Sent\$(Split-Path -Leaf $file)"
- #Place a copy in Correspondence\Archive\Printing\MMDDYYYY\Internal\Sent for permanent archival
- $archiveFile = "$(Split-Path -Parent $file)\Sent\$(Split-Path -Leaf $file)"
- $archiveFile = $archiveFile.Substring(0, $newFile.IndexOf("Printing\")) + "Archive\" + $archiveFile.Substring($newFile.IndexOf("Printing\"))
- #Create Archive dir if it doesn't exist and copy file
- if (-Not (Test-Path "$(Split-Path -Parent $archiveFile)")) {
- New-Item -ItemType directory -Path "$(Split-Path -Parent $archiveFile)" | Out-Null
- }
- Copy-Item $file -Destination $archiveFile
- #Print and move original file to inside Sent folder, will be kept for 30 days per Redwood job
- #Send to printer
- #REDACTED requested to print single sided. Command below is duplex for future reference.
- #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"
- gswin64c.exe -dPrinted -dBATCH -dNOPAUSE -dNOSAFER -q -dNumCopies=1 -dFitPage -dPSFitPage -dFIXEDMEDIA -sPAPERSIZE=a4 -sColorConversionStrategy=Gray -sDEVICE=mswinpr2 -sOutputFile="%printer%${printer}" "$file"
- Start-Sleep -Seconds 1
- #Test if file exists already first. Cannot move if already exists.
- if (Test-Path "${newFile}") {
- Move-Item -Path $newFile -Destination "${newFile}.${datetime}"
- }
- Move-Item -Path $file -Destination $newFile
- Write-Host " " $newFile.Substring($newFile.IndexOf("Files\"))
- }
- write-host "`n"
- } else {
- write-host " No Internal files found to print. `n"
- }
- write-host "Uploaded File Count: " $allFiles.Count
- write-host "`n`n`n"
- Stop-Transcript | Out-Null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement