This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
forked from rubrikinc/rubrik-scripts-for-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sla_report.ps1
453 lines (452 loc) · 28.7 KB
/
sla_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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
#Requires -Modules Rubrik
#Requires -Version 5
#Requires -PSEdition Desktop
# --------------------
# SLA Reporting Script
# --------------------
# This script will report on all SLA Domains on a Rubrik cluster, detailing:
# - SLA Domain Name
# - Frequency and retention settings
# - Replication settings
# - Archival settings
# - Member objects
# --------------------
# Written by: Tim Hynes <tim.hynes@rubrik.com>
# --------------------
Import-Module Rubrik
# Replace variables here:
$rubrik_cluster = 'rubrik.demo.com'
$rubrik_user = 'admin'
$rubrik_pass = 'Mypass123!'
$output_type = 'csv' # enter 'html' for an html report, 'csv' for a CSV based-report, or 'text' for a plain text report
$output_folder = '.' # this can be modified to 'C:\temp' or whatever is required, leave as '.' to write to script path, do not include trailing slash on folder path
# Do not change anything after this point
# Set up web headers for certain API calls
$headers = @{
Authorization = "Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $rubrik_user,$rubrik_pass)))
Accept = 'application/json'
}
# Connect to Rubrik cluster
$rk_connection = Connect-Rubrik -Server $rubrik_cluster -Username $rubrik_user -Password $(ConvertTo-SecureString -String $rubrik_pass -AsPlainText -Force)
# Get list of all local SLAs
$rk_all_slas = Get-RubrikSla -PrimaryClusterID local
# Create our object which will contain all our output information
$output_object = @()
Write-Output "$($rk_all_slas.count) SLA Domains found on Rubrik cluster..."
# Now gather all the data we will use for the report
foreach ($rk_sla in $rk_all_slas) {
Write-Output "Working on SLA Domain: $($rk_sla.name)"
$this_sla_object = @{}
$this_sla_object['name'] = $rk_sla.name
$this_sla_object['frequencies'] = $rk_sla.frequencies
if ($rk_sla.replicationSpecs) {
$this_sla_object['replication'] = @{}
$rep_target_info = Invoke-WebRequest -Uri $("https://"+$rubrik_cluster+"/api/internal/replication/target/"+$rk_sla.replicationSpecs.locationId) -Headers $headers -Method GET
$this_sla_object['replication']['target'] = $($rep_target_info.Content | ConvertFrom-Json).targetClusterName
$this_sla_object['replication']['retention'] = $rk_sla.replicationSpecs.retentionLimit
}
if ($rk_sla.archivalSpecs) {
$this_sla_object['archive'] = @{}
$archive_locations = Invoke-WebRequest -Uri $("https://"+$rubrik_cluster+"/api/internal/archive/location") -Headers $headers -Method GET
$archive_locations = $($archive_locations.Content | ConvertFrom-Json).data
$this_sla_object['archive']['target'] = $archive_locations | Where-Object -Property id -eq $rk_sla.archivalSpecs.locationId | Select-Object -ExpandProperty name
$this_sla_object['archive']['instantArchive'] = $rk_sla.archivalSpecs.archivalThreshold
$this_sla_object['archive']['retentionOnBrik'] = $rk_sla.localRetentionLimit
}
$this_sla_object['vms'] = @()
$this_sla_vms = Get-RubrikVM -SLA $rk_sla.name
foreach ($vm in $this_sla_vms) {
$this_sla_object['vms'] += $vm.name
}
$this_sla_object['filesets'] = @()
$this_sla_filesets = Get-RubrikFileset -SLA $rk_sla.name
foreach ($fileset in $this_sla_filesets) {
$this_sla_object['filesets'] += $($fileset.hostName + ":::" + $fileset.name)
}
$this_sla_object['databases'] = @()
$this_sla_databases = Get-RubrikDatabase -Sla $rk_sla.name
foreach ($db in $this_sla_databases) {
$this_sla_object['databases'] += $($db.rootProperties.rootName + ":::" + $db.instanceName + "\" + $db.name)
}
$output_object += $this_sla_object
}
# Now we output the report
if ($output_type -eq 'text') {
$output_file_name = $output_folder + "\" + $(get-date -uFormat "%Y%m%d-%H%M%S") + "-RubrikSLAReport.txt"
Write-Output "============================================" | Tee-Object -FilePath $output_file_name -Append
Write-Output "SLA Domain Report" | Tee-Object -FilePath $output_file_name -Append
Write-Output "Rubrik Cluster: $rubrik_cluster" | Tee-Object -FilePath $output_file_name -Append
Write-Output "Date/Time: $(Get-Date)" | Tee-Object -FilePath $output_file_name -Append
Write-Output "# of SLA Domains: $($rk_all_slas.count)" | Tee-Object -FilePath $output_file_name -Append
Write-Output "============================================" | Tee-Object -FilePath $output_file_name -Append
foreach ($sla_domain in $output_object) {
Write-Output "Name: $($sla_domain.name)" | Tee-Object -FilePath $output_file_name -Append
Write-Output "" | Tee-Object -FilePath $output_file_name -Append
Write-Output "Retention Settings:" | Tee-Object -FilePath $output_file_name -Append
$retention_output = @()
$retention_output | Select-Object -Property Take,Keep
$cluster_version = $rk_connection | Where-Object {$_.Name -eq 'version'} | Select-Object -ExpandProperty Value
if ($cluster_version.split('.')[0] -lt 5) {
if ($sla_domain.frequencies.timeUnit.Contains("Hourly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Hourly"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Hour(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention / 24) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.timeUnit.Contains("Daily")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Daily"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Day(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.timeUnit.Contains("Monthly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Monthly"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Month(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention) Month(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.timeUnit.Contains("Yearly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Yearly"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Year(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention) Year(s)"
$retention_output += $this_policy
}
} else {
if ($sla_domain.frequencies.hourly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.hourly.frequency) Hour(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.hourly.retention / 24) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.daily) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.daily.frequency) Day(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.daily.retention) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.weekly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.weekly.frequency) Week(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.weekly.retention) Week(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.monthly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.monthly.frequency) Month(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.monthly.retention) Month(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.quarterly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.quarterly.frequency) Quarter(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.quarterly.retention / 4) Year(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.yearly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.yearly.frequency) Year(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.yearly.retention) Year(s)"
$retention_output += $this_policy
}
}
Write-Output $($retention_output | Format-Table) | Tee-Object -FilePath $output_file_name -Append
Write-Output "Archival Settings:" | Tee-Object -FilePath $output_file_name -Append
if ($sla_domain.archive) {
if ($sla_domain.archive.instantArchive -eq 1) {
if (0 -eq $sla_domain.archive.retentionOnBrik % 31536000 -and $sla_domain.archive.retentionOnBrik -eq 1) {
Write-Output "The SLA domain is archived to $($sla_domain.archive.target) with Instant Archive enabled, and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 31536000) years" | Tee-Object -FilePath $output_file_name -Append
} else {
Write-Output "The SLA domain is archived to $($sla_domain.archive.target) with Instant Archive enabled, and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 86400) days" | Tee-Object -FilePath $output_file_name -Append
}
} else {
if (0 -eq $sla_domain.archive.retentionOnBrik % 31536000) {
Write-Output "The SLA domain is archived to $($sla_domain.archive.target), and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 31536000) years" | Tee-Object -FilePath $output_file_name -Append
} else {
Write-Output "The SLA domain is archived to $($sla_domain.archive.target), and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 86400) days" | Tee-Object -FilePath $output_file_name -Append
}
}
} else {
Write-Output " (none)" | Tee-Object -FilePath $output_file_name -Append
}
Write-Output "" | Tee-Object -FilePath $output_file_name -Append
Write-Output "Replication Settings:" | Tee-Object -FilePath $output_file_name -Append
if ($sla_domain.replication) {
if (0 -eq $sla_domain.replication.retention % 31536000) {
Write-Output "The SLA domain is replicated to $($sla_domain.replication.target), and is kept on the remote cluster for $($sla_domain.replication.retention / 31536000) years" | Tee-Object -FilePath $output_file_name -Append
} else {
Write-Output "The SLA domain is replicated to $($sla_domain.replication.target), and is kept on the remote cluster for $($sla_domain.replication.retention / 86400) days" | Tee-Object -FilePath $output_file_name -Append
}
} else {
Write-Output " (none)" | Tee-Object -FilePath $output_file_name -Append
}
Write-Output "" | Tee-Object -FilePath $output_file_name -Append
if ($sla_domain.vms.count -gt 0) {
Write-Output "Protected Virtual Machines:" | Tee-Object -FilePath $output_file_name -Append
foreach ($vm in $sla_domain.vms) {
Write-Output " $vm" | Tee-Object -FilePath $output_file_name -Append
}
} else {
Write-Output "Protected Virtual Machines:" | Tee-Object -FilePath $output_file_name -Append
Write-Output " (none)" | Tee-Object -FilePath $output_file_name -Append
}
if ($sla_domain.databases.count -gt 0) {
Write-Output "Protected Databases:" | Tee-Object -FilePath $output_file_name -Append
foreach ($database in $sla_domain.databases) {
Write-Output " $database" | Tee-Object -FilePath $output_file_name -Append
}
} else {
Write-Output "Protected Databases:" | Tee-Object -FilePath $output_file_name -Append
Write-Output " (none)" | Tee-Object -FilePath $output_file_name -Append
}
if ($sla_domain.filesets.count -gt 0) {
Write-Output "Protected Filesets:" | Tee-Object -FilePath $output_file_name -Append
foreach ($fileset in $sla_domain.filesets) {
Write-Output " $fileset"
}
} else {
Write-Output "Protected Filesets:" | Tee-Object -FilePath $output_file_name -Append
Write-Output " (none)" | Tee-Object -FilePath $output_file_name -Append
}
Write-Output "============================================" | Tee-Object -FilePath $output_file_name -Append
}
}
if ($output_type -eq 'html') {
$output_file_name = $output_folder + "\" + $(get-date -uFormat "%Y%m%d-%H%M%S") + "-RubrikSLAReport.html"
$output_html = @()
$style_head = @"
<head><style>
P {font-family: Calibri, Helvetica, sans-serif;}
H1 {font-family: Calibri, Helvetica, sans-serif;}
H3 {font-family: Calibri, Helvetica, sans-serif;}
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TH {border-width: 1px; padding: 3px; border-style: solid; border-color: black; background-color: #00cccc; font-family: Calibri, Helvetica, sans-serif;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black; font-family: Calibri, Helvetica, sans-serif;}
</style></head>
"@
$output_html += $style_head
$output_html += "<hr>"
$output_html += "<h1>SLA Domain Report</h1>"
$output_html += "<h3>Rubrik Cluster: $rubrik_cluster</h3>"
$output_html += "<h3>Date/Time: $(Get-Date)</h3>"
$output_html += "<h3># of SLA Domains: $($rk_all_slas.count)</h3>"
$output_html += "<hr>"
foreach ($sla_domain in $output_object) {
$output_html += "<p><b>Name: </b>$($sla_domain.name)</p>"
$output_html += "<p><b>Retention Settings:</b></p>"
$retention_output = @()
$cluster_version = $rk_connection | Where-Object {$_.Name -eq 'version'} | Select-Object -ExpandProperty Value
if ($cluster_version.split('.')[0] -lt 5) {
if ($sla_domain.frequencies.timeUnit.Contains("Hourly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Hourly"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Hour(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention / 24) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.timeUnit.Contains("Daily")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Daily"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Day(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.timeUnit.Contains("Monthly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Monthly"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Month(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention) Month(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.timeUnit.Contains("Yearly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Yearly"
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($policy.frequency) Year(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($policy.retention) Year(s)"
$retention_output += $this_policy
}
} else {
if ($sla_domain.frequencies.hourly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.hourly.frequency) Hour(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.hourly.retention / 24) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.daily) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.daily.frequency) Day(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.daily.retention) Day(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.weekly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.weekly.frequency) Week(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.weekly.retention) Week(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.monthly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.monthly.frequency) Month(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.monthly.retention) Month(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.quarterly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.quarterly.frequency) Quarter(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.quarterly.retention / 4) Year(s)"
$retention_output += $this_policy
}
if ($sla_domain.frequencies.yearly) {
$this_policy = New-Object PSObject
$this_policy | Add-Member -type NoteProperty -Name 'Take' -Value "Every $($sla_domain.frequencies.yearly.frequency) Year(s)"
$this_policy | Add-Member -type NoteProperty -Name 'Keep' -Value "for $($sla_domain.frequencies.yearly.retention) Year(s)"
$retention_output += $this_policy
}
}
$output_html += $($retention_output | ConvertTo-Html -Fragment)
$output_html += "<p><b>Archival Settings:</b></p>"
if ($sla_domain.archive) {
if ($sla_domain.archive.instantArchive -eq 1) {
if (0 -eq $sla_domain.archive.retentionOnBrik % 31536000 -and $sla_domain.archive.instantArchive -eq 1) {
$output_html += "<p>The SLA domain is archived to $($sla_domain.archive.target) with Instant Archive enabled, and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 31536000) years</p>"
} else {
$output_html += "<p>The SLA domain is archived to $($sla_domain.archive.target) with Instant Archive enabled, and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 86400) days</p>"
}
} else {
if (0 -eq $sla_domain.archive.retentionOnBrik % 31536000 -and $sla_domain.archive.retentionOnBrik -ne 0) {
$output_html += "<p>The SLA domain is archived to $($sla_domain.archive.target), and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 31536000) years</p>"
} else {
$output_html += "<p>The SLA domain is archived to $($sla_domain.archive.target), and is kept on the local cluster for $($sla_domain.archive.retentionOnBrik / 86400) days</p>"
}
}
} else {
$output_html += "<p>(none)</p>"
}
$output_html += "<p><b>Replication Settings:</b></p>"
if ($sla_domain.replication) {
if (0 -eq $sla_domain.replication.retention % 31536000) {
$output_html += "<p>The SLA domain is replicated to $($sla_domain.replication.target), and is kept on the remote cluster for $($sla_domain.replication.retention / 31536000) years</p>"
} else {
$output_html += "<p>The SLA domain is replicated to $($sla_domain.replication.target), and is kept on the remote cluster for $($sla_domain.replication.retention / 86400) days</p>"
}
} else {
$output_html += "<p>(none)</p>"
}
if ($sla_domain.vms.count -gt 0) {
$output_html += "<p><b>Protected Virtual Machines:</b></p>"
$output_html += "<table>"
foreach ($vm in $sla_domain.vms) {
$output_html += "<tr><td>$vm</td></tr>"
}
$output_html += "</table>"
} else {
$output_html += "<p><b>Protected Virtual Machines:</b></p>"
$output_html += "<p>(none)</p>"
}
if ($sla_domain.databases.count -gt 0) {
$output_html += "<p><b>Protected Databases:</b></p>"
$output_html += "<table>"
foreach ($database in $sla_domain.databases) {
$output_html += "<tr><td>$database</td></tr>"
}
$output_html += "</table>"
} else {
$output_html += "<p><b>Protected Databases:</b></p>"
$output_html += "<p>(none)</p>"
}
if ($sla_domain.filesets.count -gt 0) {
$output_html += "<p><b>Protected Filesets:</b></p>"
$output_html += "<table>"
foreach ($fileset in $sla_domain.filesets) {
$output_html += "<tr><td>$fileset</td></tr>"
}
$output_html += "</table>"
} else {
$output_html += "<p><b>Protected Filesets:</b></p>"
$output_html += "<p>(none)</p>"
}
$output_html += "<hr>"
}
$output_html > $output_file_name
}
if ($output_type -eq 'csv') {
$output_file_name = $output_folder + "\" + $(get-date -uFormat "%Y%m%d-%H%M%S") + "-RubrikSLAReport.csv"
$output_csv = @()
$output_array = @()
foreach ($sla_domain in $output_object) {
$row = '' | Select-Object name,cluster,timedate,policy_hourly,policy_daily,policy_weekly,policy_monthly,policy_quarterly,policy_yearly,archival_location,archival_instant,archival_local_retention,replication_location,replication_target_retention,protected_vms,protected_dbs,protected_filesets
$row.name = $sla_domain.name
$row.cluster = $rubrik_cluster
$row.timedate = $(Get-Date)
$cluster_version = $rk_connection | Where-Object {$_.Name -eq 'version'} | Select-Object -ExpandProperty Value
if ($cluster_version.split('.')[0] -lt 5) {
if ($sla_domain.frequencies.timeUnit.Contains("Hourly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Hourly"
$row.policy_hourly = "Take every $($policy.frequency) Hour(s), keep for $($policy.retention / 24) Day(s)"
}
if ($sla_domain.frequencies.timeUnit.Contains("Daily")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Daily"
$row.policy_daily = "Take every $($policy.frequency) Day(s), keep for $($policy.retention) Day(s)"
}
if ($sla_domain.frequencies.timeUnit.Contains("Monthly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Monthly"
$row.policy_monthly = "Take every $($policy.frequency) Month(s), keep for $($policy.retention) Month(s)"
}
if ($sla_domain.frequencies.timeUnit.Contains("Yearly")) {
$policy = $sla_domain.frequencies | Where-Object -Property timeUnit -eq "Yearly"
$row.policy_yearly = "Take every $($policy.frequency) Year(s), keep for $($policy.retention) Year(s)"
}
} else {
if ($sla_domain.frequencies.hourly) {
$row.policy_hourly = "Take every $($sla_domain.frequencies.hourly.frequency) Hour(s), keep for $($sla_domain.frequencies.hourly.retention / 24) Day(s)"
}
if ($sla_domain.frequencies.daily) {
$row.policy_daily = "Take every $($sla_domain.frequencies.daily.frequency) Day(s), keep for $($sla_domain.frequencies.daily.retention) Day(s)"
}
if ($sla_domain.frequencies.weekly) {
$row.policy_weekly = "Take every $($sla_domain.frequencies.weekly.frequency) Week(s), keep for $($sla_domain.frequencies.weekly.retention) Week(s)"
}
if ($sla_domain.frequencies.monthly) {
$row.policy_monthly = "Take every $($sla_domain.frequencies.monthly.frequency) Month(s), keep for $($sla_domain.frequencies.monthly.retention) Month(s)"
}
if ($sla_domain.frequencies.quarterly) {
$row.policy_quarterly = "Take every $($sla_domain.frequencies.quarterly.frequency) Quarter(s), keep for $($sla_domain.frequencies.quarterly.retention / 4) Year(s)"
}
if ($sla_domain.frequencies.yearly) {
$row.policy_yearly = "Take every $($sla_domain.frequencies.yearly.frequency) Year(s), keep for $($sla_domain.frequencies.yearly.retention) Year(s)"
}
}
if ($sla_domain.archive.target) {
$row.archival_location = $sla_domain.archive.target
}
if ($sla_domain.archive.instantArchive -eq 1) {
$row.archival_instant = $true
} else {
$row.archival_instant = $false
}
if ($sla_domain.archive.retentionOnBrik) {
if (0 -eq $sla_domain.archive.retentionOnBrik % 31536000) {
$row.archival_local_retention = "$($sla_domain.archive.retentionOnBrik / 31536000) years"
} else {
$row.archival_local_retention = "$($sla_domain.archive.retentionOnBrik / 86400) days"
}
}
if ($sla_domain.replication) {
$row.replication_location = $sla_domain.replication.target
if (0 -eq $sla_domain.replication.retention % 31536000 -and $sla_domain.replication.retention -ne 0) {
$row.replication_target_retention = "$($sla_domain.replication.retention / 31536000) years"
} else {
$row.replication_target_retention = "$($sla_domain.replication.retention / 86400) days"
}
}
$row.protected_vms = $($sla_domain.vms -join ';')
$row.protected_dbs = $($sla_domain.databases -join ';')
$row.protected_filesets = $($sla_domain.filesets -join ';')
$output_array += $row
}
$output_csv += $output_array | ConvertTo-Csv
$output_csv > $output_file_name
}