@@ -18,6 +18,7 @@ function Get-CVJob {
18
18
19
19
. DESCRIPTION
20
20
Get the list of all jobs. Based on parameters this commandlet filters the output.
21
+ This method is implemented with Powershell paging support.
21
22
22
23
. PARAMETER ClientName
23
24
Filter output based on ClientName.
@@ -37,8 +38,32 @@ function Get-CVJob {
37
38
. PARAMETER Details
38
39
Retrieves the details for a job.
39
40
41
+ . PARAMETER limit
42
+ The number of results to be listed in a page. Used for changing the paging limits. By default, the limit is 100 results per page.
43
+
44
+ . PARAMETER First
45
+ Get list of jobs with paging support -First 20 (20 per page).
46
+
47
+ . PARAMETER Skip
48
+ Get list of jobs with paging support -First 20 -Skip 5 (20 per page, skip first 5 jobs).
49
+
50
+ . PARAMETER IncludeTotalCount
51
+ Include total count of result record set.
52
+
40
53
. EXAMPLE
41
54
Get-CVJob
55
+
56
+ . EXAMPLE
57
+ Get-CVJob -CompletedTime 8 -IncludeTotalCount
58
+
59
+ . EXAMPLE
60
+ Get-CVJob -CompletedTime 72 -IncludeTotalCount -First 5
61
+
62
+ . EXAMPLE
63
+ Get-CVJob -CompletedTime 240 -IncludeTotalCount -First 10 -Skip 0
64
+
65
+ . EXAMPLE
66
+ Get-CVJob -CompletedTime 240 -IncludeTotalCount -First 10 -Skip 20
42
67
43
68
. EXAMPLE
44
69
Get-CVJob -Details
@@ -68,7 +93,7 @@ function Get-CVJob {
68
93
Author: Gary Stoops
69
94
Company: Commvault
70
95
#>
71
- [CmdletBinding (DefaultParameterSetName = ' Default' )]
96
+ [CmdletBinding (SupportsPaging = $True , DefaultParameterSetName = ' Default' )]
72
97
[OutputType ([PSCustomObject ])]
73
98
param (
74
99
[Parameter (Mandatory = $False , ParameterSetName = ' ById' , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
@@ -96,6 +121,10 @@ function Get-CVJob {
96
121
[ValidateNotNullorEmpty ()]
97
122
[Int32 ] $CompletedTime = 24 , # default 24 hours
98
123
124
+ [Parameter (Mandatory = $False , ParameterSetName = ' Default' )]
125
+ [ValidateNotNullorEmpty ()]
126
+ [Int32 ] $limit = 100 ,
127
+
99
128
[Switch ] $Details
100
129
)
101
130
@@ -150,10 +179,13 @@ function Get-CVJob {
150
179
}
151
180
else {
152
181
if (-not [String ]::IsNullOrEmpty($ClientName )) {
153
- $clientObj = Get-CVClient - Client $ClientName
182
+ $clientObj = Get-CVId - ClientName $ClientName
154
183
if ($null -ne $clientObj ) {
155
184
$sessionObj.requestProps.endpoint += ' &clientId=' + $clientObj.clientId
156
185
}
186
+ else {
187
+ return
188
+ }
157
189
}
158
190
159
191
if (-not [String ]::IsNullOrEmpty($SubclientName )) {
@@ -167,7 +199,9 @@ function Get-CVJob {
167
199
$subclientId = $subclientObj.subclientId
168
200
}
169
201
}
170
-
202
+
203
+ $sessionObj.requestProps.endpoint += " &hideAdminjobs=false"
204
+
171
205
if (-not [String ]::IsNullOrEmpty($JobFilter )) {
172
206
$sessionObj.requestProps.endpoint += ' &jobFilter=' + $JobFilter
173
207
}
@@ -182,8 +216,26 @@ function Get-CVJob {
182
216
else {
183
217
$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace (' {completedJobLookupTime}' , $null )
184
218
}
219
+
220
+ if ($limit ) {
221
+ $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace (' {limit}' , $limit )
222
+ }
223
+ else {
224
+ $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace (' {limit}' , $null )
225
+ }
185
226
186
- $headerObj = Get-CVRESTHeader $sessionObj
227
+ if ($PSCmdlet.PagingParameters.First -eq [Uint64 ]::MaxValue) { # MaxValue is system default
228
+ if ($PSCmdlet.PagingParameters.IncludeTotalCount.IsPresent ) {
229
+ $headerObj = Get-CVRESTHeader $sessionObj - Limit 0 - Offset 0
230
+ }
231
+ else {
232
+ $headerObj = Get-CVRESTHeader $sessionObj
233
+ }
234
+ }
235
+ else {
236
+ $headerObj = Get-CVRESTHeader $sessionObj - Limit $PSCmdlet.PagingParameters.First - Offset $PSCmdlet.PagingParameters.Skip
237
+ }
238
+
187
239
$body = ' '
188
240
$payload = @ { }
189
241
$payload.Add (' headerObject' , $headerObj )
@@ -240,12 +292,16 @@ function Get-CVJob {
240
292
}
241
293
242
294
end { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : end"
295
+ if ($PSCmdlet.PagingParameters.IncludeTotalCount ) {
296
+ [double ] $accuracy = 1.0
297
+ $PSCmdlet.PagingParameters.NewTotalCount ($response.Content.totalRecordsWithoutPaging , $accuracy )
298
+ }
243
299
}
244
300
}
245
301
246
302
247
303
function Get-CVJobDetail {
248
- <#
304
+ <#
249
305
. SYNOPSIS
250
306
Gets extended details for a job.
251
307
@@ -255,6 +311,9 @@ function Get-CVJobDetail {
255
311
. PARAMETER Id
256
312
Gets extended details for the job specified by Id.
257
313
314
+ . PARAMETER InfoType
315
+ Gets additional job information.
316
+
258
317
. PARAMETER JobObject
259
318
Gets extended details for the job specified by piped JobObject.
260
319
@@ -276,6 +335,9 @@ function Get-CVJobDetail {
276
335
. EXAMPLE
277
336
Get-CVJobDetail -Id 175 | Select-Object -ExpandProperty progressInfo
278
337
338
+ . EXAMPLE
339
+ Get-CVJobDetail -Id 175 InfoType 1
340
+
279
341
. OUTPUTS
280
342
Outputs [PSCustomObject] containing result.
281
343
@@ -292,53 +354,91 @@ function Get-CVJobDetail {
292
354
[ValidateNotNullorEmpty ()]
293
355
[Int32 ] $Id ,
294
356
357
+ [Parameter (Mandatory = $False , ParameterSetName = ' ById' , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
358
+ [ValidateNotNullorEmpty ()]
359
+ [Int32 ] $InfoType ,
360
+
295
361
[Parameter (Mandatory = $True , ParameterSetName = ' ByObject' , ValueFromPipeline = $True , ValueFromPipelineByPropertyName = $True )]
296
362
[ValidateNotNullorEmpty ()]
297
363
[System.Object ] $JobObject
298
364
)
299
365
300
- begin { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : begin"
366
+ begin {
367
+ Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : begin"
301
368
302
369
try {
303
- $sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
304
- $endpointSave = $sessionObj.requestProps.endpoint
370
+ if ($InfoType -eq 0 ) {
371
+ $sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
372
+ $endpointSave = $sessionObj.requestProps.endpoint
373
+ }
374
+ else {
375
+ $sessionObj = Get-CVSessionDetail ' GetJobById'
376
+ $endpointSave = $sessionObj.requestProps.endpoint
377
+ }
305
378
}
306
379
catch {
307
380
throw $_
308
381
}
309
382
}
310
383
311
- process { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : process"
384
+ process {
385
+ Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : process"
312
386
313
387
try {
314
- $sessionObj.requestProps.endpoint = $endpointSave
388
+ if ($InfoType -gt 0 ) {
389
+ if ($PSCmdlet.ParameterSetName -eq ' ById' ) {
390
+ $job_id = $Id
391
+ }
392
+ else {
393
+ $job_id = $JobObject.jobId
394
+ }
395
+ $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace (' {jobId}' , ($job_id ))
396
+ $sessionObj.requestProps.endpoint = -join ($sessionObj.requestProps.endpoint , " /AdvancedDetails?infoType=" , $InfoType )
397
+ $body = ' '
398
+ $headerObj = Get-CVRESTHeader $sessionObj
399
+ $payload = @ { }
400
+ $payload.Add (' headerObject' , $headerObj )
401
+ $payload.Add (' body' , $body )
402
+ $validate = ' '
315
403
316
- $headerObj = Get-CVRESTHeader $sessionObj
317
- $jobObj = @ { }
318
- if ($PSCmdlet.ParameterSetName -eq ' ById' ) {
319
- $jobObj.Add (' jobId' , $Id )
404
+ $response = Submit-CVRESTRequest $payload $validate
405
+
406
+ if ($response.IsValid ) {
407
+ Write-Output $response.Content
408
+ }
320
409
}
321
410
else {
322
- $jobObj.Add (' jobId' , $JobObject.jobId )
323
- }
324
- $body = $jobObj | ConvertTo-Json - Depth 10
325
- $payload = @ { }
326
- $payload.Add (' headerObject' , $headerObj )
327
- $payload.Add (' body' , $body )
328
- $validate = ' job'
329
-
330
- $response = Submit-CVRESTRequest $payload $validate
411
+ $sessionObj.requestProps.endpoint = $endpointSave
331
412
332
- if ($response.IsValid ) {
333
- Write-Output $response.Content.job.jobDetail
413
+ $headerObj = Get-CVRESTHeader $sessionObj
414
+ $jobObj = @ { }
415
+ if ($PSCmdlet.ParameterSetName -eq ' ById' ) {
416
+ $jobObj.Add (' jobId' , $Id )
417
+ }
418
+ else {
419
+ $jobObj.Add (' jobId' , $JobObject.jobId )
420
+ }
421
+ $body = $jobObj | ConvertTo-Json - Depth 10
422
+ $payload = @ { }
423
+ $payload.Add (' headerObject' , $headerObj )
424
+ $payload.Add (' body' , $body )
425
+ $validate = ' job'
426
+
427
+ $response = Submit-CVRESTRequest $payload $validate
428
+
429
+ if ($response.IsValid ) {
430
+ Write-Output $response.Content.job.jobDetail
431
+ }
334
432
}
433
+
335
434
}
336
435
catch {
337
436
throw $_
338
437
}
339
438
}
340
439
341
- end { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : end"
440
+ end {
441
+ Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : end"
342
442
}
343
443
}
344
444
@@ -485,7 +585,75 @@ function Resume-CVJob {
485
585
end { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : end"
486
586
}
487
587
}
488
-
588
+ function Resubmit-CVJob {
589
+ <#
590
+ . SYNOPSIS
591
+ Resubmit the job specified by job Id.
592
+
593
+ . DESCRIPTION
594
+ Resubmit the job specified by job Id.
595
+
596
+ . PARAMETER JobId
597
+ Resubmit the job specified by JobId.
598
+
599
+ . EXAMPLE
600
+ Resubmit-CVJob -JobId 78
601
+
602
+ . OUTPUTS
603
+ Outputs [PSCustomObject] containing result.
604
+
605
+ . NOTES
606
+ Author: Jnanesh D
607
+ Company: Commvault
608
+ #>
609
+ [CmdletBinding ()]
610
+ [OutputType ([PSCustomObject ])]
611
+ param (
612
+ [Parameter (Mandatory = $True )]
613
+ [ValidateNotNullorEmpty ()]
614
+ [Int32 ] $JobId
615
+ )
616
+
617
+ begin { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : begin"
618
+
619
+ try {
620
+ $sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
621
+ $endpointSave = $sessionObj.requestProps.endpoint
622
+ }
623
+ catch {
624
+ throw $_
625
+ }
626
+ }
627
+
628
+ process { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : process"
629
+
630
+ try {
631
+ $sessionObj.requestProps.endpoint = $endpointSave
632
+ $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace (' {jobId}' , $JobId )
633
+
634
+ $headerObj = Get-CVRESTHeader $sessionObj
635
+ $body = ' '
636
+ $payload = @ { }
637
+ $payload.Add (' headerObject' , $headerObj )
638
+ $payload.Add (' body' , $body )
639
+
640
+ $response = Submit-CVRESTRequest $payload ' jobIds'
641
+
642
+ if ($response.IsValid ) {
643
+ Write-Output $response.Content
644
+ }
645
+ else {
646
+ Write-Information - InformationAction Continue - MessageData " INFO: $ ( $MyInvocation.MyCommand ) : resume request was not succesfully submitted for job [$JobId ]"
647
+ }
648
+ }
649
+ catch {
650
+ throw $_
651
+ }
652
+ }
653
+
654
+ end { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : end"
655
+ }
656
+ }
489
657
490
658
function Stop-CVJob {
491
659
<#
@@ -1603,4 +1771,4 @@ function PrepareSendLogFilesBodyJson ($PrepInputs) {
1603
1771
catch {
1604
1772
throw $_
1605
1773
}
1606
- }
1774
+ }
0 commit comments