-
Notifications
You must be signed in to change notification settings - Fork 0
/
nw_libraries_report.ps1
140 lines (119 loc) · 4.28 KB
/
nw_libraries_report.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#----------------------------------------------------------------------
# Name: Report tape status on all jukeboxes(libraries)
# also VTLs, DD VTLs
# Version: 1.0.0.0
# Author: George Dicu
# Start date: 28.12.2015
# Release date: xx.12.2015
# Description:
#
# Author:
# Department: Cloud, Backup, RO
#--------------------------------------------------------------------
$libraries = @()
$container = @()
$hn = hostname
[string]$attch = ""
#//////////////////////////////////////////
#CONSTANTS
#//////////////////////////////////////////
#If you want to include the DataDomain,
#change $DD = $false to $DD = $true
#by default it`s exluded
$DD = $false
#If you want to do a fastinventory on jukeboxes
#change $fastinventory = $false to $fastinventory = $true
#by default it`s exluded
$fastinventory = $false
#Mail variables, you can change the content of them as you need
$to = "[email protected]"
$subject = $hn.ToUpper()+" Tape Libraries Status"
$body = "Hello,||This is an automated tape status report on "+$hn.ToUpper()+" Libraries||RO Backup Team"
#save script path location
$path = "D:\nsr\scripts"
#//////////////////////////////////////////
#SCRIPT BLOCK
#//////////////////////////////////////////
#trim Library name from double quotes char
function trim {
$args[0] = $args[0] -replace "`"",""
return $args[0]
}
#nsramdin command
$nsrjukeboxes =
@"
. type: NSR jukebox
show name;comment;enabled
print
"@
#save nsradmin output after execution
$jukeboxes = $nsrjukeboxes | nsradmin.exe -i -
$jbsname = $jukeboxes -match "name:"
$jbscomment = $jukeboxes -match "comment:"
$jbsenabled = $jukeboxes -match "enabled:"
$i = 0
foreach($jbname in $jbsname){
$PropertyHash = @{}
$PropertyHash = @{
"Name" = trim($jbname.split(":",2)[-1].trim() -replace ";","")
"Comment" = $jbscomment[$i].split(":",2)[-1].trim() -replace ";",""
"Enabled" = $jbsenabled[$i].split(":",2)[-1].trim() -replace ";",""
}
$container += New-Object -TypeName PSObject -Property $PropertyHash
$i++
}
$i = 0
$jbblat = @()
foreach ($jb in $container){
if(!$DD){
if($jb.Comment -eq "DataDomain") {
continue
}
}
if($jb.Enabled -eq "No") {
continue
}
#this v is only for blat to send all files at once
$jbblat += $jb.Name
#create new variable name dinamicly for all Libraries.
#we create it with JB+$i because we can have Libraries Names who can be incompatible with variable names
#New-Variable -Name ($jb.Name)
$jbtmp = $jb.Name
Set-Variable -name $jb.Name -Value (mminfo -aot -xc~ -q "family=tape,location=$jbtmp" -r "pool,barcode,volretent,location,%used")
$tmp = @()
$tmp2 = @()
#saveing current jukebox
$tmp2 = nsrjb -C -j $jbtmp
$tmp2 = $tmp2[3..($tmp2.count-1)]
$jbcontainer = @()
#Fast Inventory Robot
if($fastinventory){
nsrjb -j $jbtmp -IIq
}
foreach($item in (Get-Variable -name $jbtmp -ValueOnly)[1..((Get-Variable -name $jbtmp -ValueOnly).Count-1)]){
$item = ($item.trim()).split("~")
$jbhash = @{}
$jbhash = @{
"Slot" = (((($tmp2 -match $item[1])[0]).trim()) -replace "\s+",";").split(";")[0] -replace ":",""
"Pool" = $item[0]
"Barcode" = $item[1]
"Expires" = $item[2]
"Used" = $item[4]
"Location" = $item[3]
"VolumeID" = (((($tmp2 -match $item[1])[0]).trim()) -replace "\s+",";").split(";")[4]
"Recyclable" = (((($tmp2 -match $item[1])[0]).trim()) -replace "\s+",";").split(";")[5]
}
$jbcontainer += New-Object -TypeName PSObject -Property $jbhash
}
Set-Variable -name $jbtmp -Value $jbcontainer
$jbtmp2 = $jbtmp -replace ":",""
(Get-Variable -Name $jbtmp -ValueOnly) | Export-Csv "$path\$jbtmp2.csv" -Delimiter ";" -NoTypeInformation -Force
$i++
}
foreach ($item in $jbblat) {
$comma = @{$true="";$false=","}[$item -eq $jbblat[-1]]
$item = $item -replace ":",""
$attch += "`"$($item).csv`"$comma"
}
cd $path
blat -to $to -subject $subject -body $body -attach $attch