-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReportEmptySlots.ps1
65 lines (41 loc) · 1.77 KB
/
ReportEmptySlots.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<#
ReportEmptySlots.ps1 / ngwmddgh / 2018-02-11
Polls a BackupExec Library's slots and if any are empty, then email the list, else quit silently.
Useful when you have a library that should always be full of tapes.
Note: You must have already bemcli.psd from BackupExec.
#>
import-module "c:\path\to\bemcli.psd1"
##### Define variables
# Which address(es) will receive the report
$recipients = "Recipient <[email protected]>"
# Which address will send the report
$sender = "Sender <[email protected]>"
# SMTP server to handle report
$SMTPserver = smtp.domain.tld
# Define the target library by its name in BackupExec
$LibraryName = "BackupExec Library Name"
# Set the number of slots in the library
$LibrarySlots = 16
##### Execute operations
# Scan the slots now to ensure accuracy
Submit-BEScanJob -RoboticLibraryDevice $LibraryName
# Sleep for 60 seconds to give the BEScanJob time to complete, since otherwise results may be inaccurate
Start-Sleep -s 60
# Create an object containing all non-cleaning slot names where BE says there is no media loaded
$EmptySlots = Get-BERoboticLibrarySlot -RoboticLibraryDevice $LibraryName | where-object {($_.Media -like '') -and !($_.IsCleaningSlot)} | Select-Object -first $LibrarySlots
if ($EmptySlots)
{
# Insert a newline between each empty slot for easy reading
$EmptySlotsList = $EmptySlots -join "`n"
$body = @"
The following slots appear empty to BackupExec, please load tapes or correct the misidentification...
$EmptySlotsList
This notice was generated by \\server\path\to\ReportEmptySlots.ps1
"@
send-mailmessage -from $sender `
-to $recipients `
-subject "Empty Slots detected in $LibraryName" `
-body "$body" `
-priority High `
-smtpServer $SMTPserver
}