Created
August 12, 2023 23:59
-
-
Save frederickding/1aa526fafa4be68228872019edc03ecd to your computer and use it in GitHub Desktop.
Veeam Tape Backup post-job receipt script for ESC/POS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module Veeam.Backup.PowerShell | |
$outputBuilder = New-Object System.Text.StringBuilder | |
[void]$outputBuilder.AppendLine('ESC "@"') | |
[void]$outputBuilder.AppendLine('ESC "2"') | |
$job = Get-VBRTapeJob -Name ExampleJobName | |
$lastjob = (Get-VBRTapeBackupSession -Job $job | Sort-Object EndTime | Select-Object -Last 1) | |
# get the tape name | |
$tape = (Get-VBRTapeMedium -MediaPool $job.Target | Sort-Object LastWriteTime | Select-Object -Last 1) | |
$stats = ($tape | Select @{Name="Free"; Expression={[math]::round($_.Free/1GB, 2)}}, @{Name="Capacity"; Expression={[math]::round($_.Capacity/1GB, 0)}}, @{Name="Percent"; Expression={[math]::round(100*($_.Capacity - $_.Free) / $_.Capacity, 1)}}) | |
# print in ESC/POS | |
# barcode first | |
[void]$outputBuilder.AppendLine('ESC "a" 1') | |
[void]$outputBuilder.AppendLine('GS "h" 40 GS "H" 0 ') | |
[void]$outputBuilder.AppendLine('GS "k" 4 "' + $tape.Name + '" 0') | |
[void]$outputBuilder.AppendLine('ESC "d" 1') | |
[void]$outputBuilder.AppendLine('ESC "a" 1') | |
[void]$outputBuilder.AppendLine('GS "!" 0x11') | |
[void]$outputBuilder.AppendLine('"' + $tape.Name + '" LF') | |
[void]$outputBuilder.AppendLine('GS "!" 0x00') | |
[void]$outputBuilder.AppendLine("`"------------------------------------------`" LF") | |
[void]$outputBuilder.AppendLine('"' + ($tape.Description -split '\n')[0] + '" LF') | |
[void]$outputBuilder.AppendLine('"Free: ' + $stats.Free + ' GB | "') | |
[void]$outputBuilder.AppendLine('"Capacity: ' + $stats.Capacity + ' GB" LF') | |
[void]$outputBuilder.AppendLine('"Used: ' + $stats.Percent + '%" LF') | |
[void]$outputBuilder.AppendLine("`"------------------------------------------`" LF") | |
[void]$outputBuilder.AppendLine('ESC "d" 2') | |
[void]$outputBuilder.AppendLine('ESC "a" 0') | |
# get the job log | |
$log = ($lastjob.Log | Sort Time | Select -ExpandProperty Title) | |
foreach($line in $log) { | |
[void]$outputBuilder.AppendLine('"' + $line + '" LF') | |
} | |
[void]$outputBuilder.AppendLine('ESC "a" 1') | |
[void]$outputBuilder.AppendLine("`"------------------------------------------`" LF") | |
[void]$outputBuilder.AppendLine('"' + $(Get-Date -Format "ddd yyyy-MM-dd HH:mm") + '" CR LF') | |
[void]$outputBuilder.AppendLine('ESC "d" 3') | |
[void]$outputBuilder.Append("GS `"V`" 65 30 FF") | |
[System.IO.File]::WriteAllLines('.\escpos.txt', $outputBuilder.ToString()) | |
senddat.exe .\escpos.txt 192.168.1.234 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment