Skip to content

Commit bd921e6

Browse files
committed
Enhancement : New commandlets
1 parent 14db882 commit bd921e6

File tree

4 files changed

+209
-2
lines changed

4 files changed

+209
-2
lines changed
1010 Bytes
Binary file not shown.

Modules/Commvault.CommCell/Commvault.CommCell.psm1

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,189 @@ function Get-CVClientGroup {
532532
}
533533
}
534534

535+
function Add-EntitytoSchedulePolicy {
536+
<#
537+
.SYNOPSIS
538+
Method to add an entity to a schedule policy
539+
540+
.DESCRIPTION
541+
Method to add an entity to a schedule policy
542+
543+
.LINK
544+
https://documentation.commvault.com/11.24/essential/48824_rest_api_post_schedule_policy_add_entity.html
545+
546+
.PARAMETER taskId
547+
Schedule policy ID
548+
549+
.OUTPUTS
550+
Outputs [PSCustomObject]
551+
552+
.EXAMPLE
553+
PS C:\>$body = "subclientId=300"
554+
PS C:\>$policy = Get-CVSchedulePolicy -Name testpolicy
555+
PS C:\>$policy | Add-EntitytoSchedulePolicy -Body $body -Forc
556+
557+
Output:
558+
errorMessage errorCode
559+
------------ ---------
560+
0
561+
.NOTES
562+
Author: Jnanesh D
563+
Company: Commvault
564+
#>
565+
566+
[CmdletBinding(DefaultParameterSetName = 'Default')]
567+
[OutputType([PSCustomObject])]
568+
param(
569+
570+
[Parameter(Mandatory= $True, ParameterSetName="ByObject", ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
571+
[ValidateNotNullorEmpty()]
572+
[System.Object] $taskObject,
573+
574+
[Alias('RequestBody')]
575+
[Parameter(Mandatory = $True)]
576+
[ValidateNotNullorEmpty()]
577+
[PSObject] $Body,
578+
579+
[Switch] $Force,
580+
581+
# Parameter help description
582+
[Parameter(Mandatory= $True, ParameterSetName="ById")]
583+
[ValidateNotNullorEmpty()]
584+
[Int64] $taskId
585+
586+
)
587+
begin{
588+
Write-Debug -Message "$($MyInvocation.MyCommand): process"
589+
try {
590+
$sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
591+
$endpointSave = $sessionObj.requestProps.endpoint
592+
}
593+
catch {
594+
throw $_
595+
}
596+
}
597+
process { Write-Debug -Message "$($MyInvocation.MyCommand): process"
598+
599+
try {
600+
$sessionObj.requestProps.endpoint = $endpointSave
601+
if ($PSCmdlet.ParameterSetName -eq "ById"){
602+
$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{taskId}', $taskId)
603+
}
604+
else {
605+
$taskId = $taskObject.task.taskId
606+
$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{taskId}', $taskId)
607+
}
608+
609+
$body = $Body
610+
$payload = @{ }
611+
$headerObj = Get-CVRESTHeader $sessionObj
612+
$payload.Add('headerObject', $headerObj)
613+
$payload.Add('body', $body)
614+
$validate = 'errorMessage'
615+
616+
if ($Force) {
617+
$response = Submit-CVRESTRequest $payload $validate
618+
Write-Output $response.Content
619+
}
620+
else {
621+
$response = Submit-CVRESTRequest $payload $validate -DryRun
622+
}
623+
624+
}
625+
catch {
626+
throw $_
627+
}
628+
}
629+
630+
end { Write-Debug -Message "$($MyInvocation.MyCommand): end"
631+
}
632+
}
633+
634+
function Set-CVSubclient {
635+
<#
636+
.SYNOPSIS
637+
Method to create a new subclient.
638+
639+
.DESCRIPTION
640+
Method to create a new subclient.
641+
642+
.PARAMETER Body
643+
Request body for the subclient creation : Refer to https://documentation.commvault.com/11.24/essential/49174_rest_api_post_subclient.html.
644+
645+
.EXAMPLE
646+
PS C:\>$req = @"
647+
{
648+
"subClientProperties": {
649+
"subClientEntity": {
650+
"clientName": "Side1",
651+
"appName": "File System",
652+
"backupsetName": "DefaultBackupset",
653+
"subclientName": "subclient001"
654+
}
655+
}
656+
}
657+
"@
658+
PS C:\>$propobj = $prop | ConvertFrom-Json
659+
PS C:\>Set-CVSubclient -body $propobj
660+
661+
.OUTPUTS
662+
Outputs [PSCustomObject]
663+
664+
.NOTES
665+
Author: Jnanesh D
666+
Company: Commvault
667+
#>
668+
[CmdletBinding(DefaultParameterSetName = 'Default',SupportsShouldProcess)]
669+
[OutputType([PSCustomObject])]
670+
param(
671+
[Alias('RequestBody')]
672+
[Parameter(Mandatory = $True)]
673+
[ValidateNotNullorEmpty()]
674+
[PSObject] $Body,
675+
676+
[Switch] $Force
677+
)
678+
679+
begin { Write-Debug -Message "$($MyInvocation.MyCommand): begin"
680+
681+
try {
682+
$sessionObj = Get-CVSessionDetail $MyInvocation.MyCommand.Name
683+
$endpointSave = $sessionObj.requestProps.endpoint
684+
}
685+
catch {
686+
throw $_
687+
}
688+
}
689+
process { Write-Debug -Message "$($MyInvocation.MyCommand): process"
690+
691+
try {
692+
$sessionObj.requestProps.endpoint = $endpointSave
693+
$body = ($Body | ConvertTo-Json -Depth 10)
694+
$payload = @{ }
695+
$headerObj = Get-CVRESTHeader $sessionObj
696+
$payload.Add('headerObject', $headerObj)
697+
$payload.Add('body', $body)
698+
$validate = 'errorMessage'
699+
700+
if ($Force -or $PSCmdlet.ShouldProcess($Body)) {
701+
$response = Submit-CVRESTRequest $payload $validate
702+
}
703+
else {
704+
$response = Submit-CVRESTRequest $payload $validate -DryRun
705+
}
706+
Write-Output $response.Content
707+
}
708+
catch {
709+
throw $_
710+
}
711+
}
712+
713+
end { Write-Debug -Message "$($MyInvocation.MyCommand): end"
714+
}
715+
716+
}
717+
535718

536719
function Get-CVSubclient {
537720
<#

Modules/Commvault.RESTSession/Commvault.RESTSession.psm1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,20 @@ function GetAPIDetail ([String] $Request) {
735735
Body = ''
736736

737737
}
738+
739+
'Set-CVSubclient' = @{
740+
Description = 'Add new subclient'
741+
Endpoint = 'Subclient'
742+
Method = 'Post'
743+
Body = ''
744+
}
745+
746+
'Add-EntitytoSchedulePolicy' = @{
747+
Description = 'Add entity to schedule policy'
748+
Endpoint = 'Task/{taskId}/Entity/Add'
749+
Method = 'Post'
750+
Body = ''
751+
}
738752

739753
'GetSubclientProperties' = @{
740754

@@ -1256,7 +1270,7 @@ function GetAPIDetail ([String] $Request) {
12561270
'Backup-CVVirtualMachine' = @{
12571271

12581272
Description = 'Starts backup job for specified virtual machine'
1259-
Endpoint = '/v2/vsa/vm/{vmGUID}/backup'
1273+
Endpoint = '/v2/vsa/vm/{vmGUID}/backup?backupLevel={backupType}'
12601274
Method = 'Post'
12611275
Body = ''
12621276
}

Modules/Commvault.VirtualServer/Commvault.VirtualServer.psm1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ function Backup-CVVirtualMachine {
550550
.PARAMETER Protected
551551
Use this switch to filter legacy, unprotected virtual machines when specifed by Name.
552552
553+
.PARAMETER BackupType
554+
Backup Type for the backup of Virtual Machine , default is INCREMENTAL . Supported values are FULL, INCREMENTAL, DIFFERENTIAL, SYNTHETIC_FULL
555+
553556
.PARAMETER Force
554557
Switch to Force override of default 'WhatIf' confirmation behavior.
555558
@@ -559,6 +562,9 @@ function Backup-CVVirtualMachine {
559562
.EXAMPLE
560563
Backup-CVVirtualMachine -Name 2208 -ClientName V1-VSAQA
561564
565+
.EXAMPLE
566+
Backup-CVVirtualMachine -Id 500b0375-4728-588f-3d69-2d64b5291bcf -BackupType FULL
567+
562568
.OUTPUTS
563569
Outputs [PSCustomObject] containing job submission result.
564570
@@ -587,6 +593,9 @@ function Backup-CVVirtualMachine {
587593
[ValidateNotNullorEmpty()]
588594
[System.Object] $ClientObject,
589595

596+
[Parameter(Mandatory = $False)]
597+
[CVBackupType] $BackupType = 'INCREMENTAL',
598+
590599
[Switch] $Protected,
591600
[Switch] $Force
592601
)
@@ -643,6 +652,7 @@ function Backup-CVVirtualMachine {
643652
}
644653

645654
$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{vmGUID}', $vmObj.strGUID)
655+
$sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace ('{backupType}', [Convert]::ToString($BackupType))
646656

647657
$headerObj = Get-CVRESTHeader $sessionObj
648658
$body = ''
@@ -2244,4 +2254,4 @@ function ValidatePagingParameters($PagingParameters, [UInt64] $TotalCount) {
22442254
function HasProperty($Object, $PropertyName)
22452255
{
22462256
$PropertyName -in $Object.PSobject.Properties.Name
2247-
}
2257+
}

0 commit comments

Comments
 (0)