@@ -304,7 +304,7 @@ function Get-CVVirtualMachine {
304304 }
305305 else { # ByDefault
306306 # query with startPage=0, pageSize=0 to get totalRecords
307- $pagingInfo = ' 0,0 '
307+ $pagingInfo = ' 0,999999 '
308308 $headerObj = Get-CVRESTHeader $sessionObj - PagingInfo $pagingInfo
309309 $body = ' '
310310 $payload = @ {}
@@ -1211,9 +1211,8 @@ function Restore-CVVirtualMachine {
12111211. PARAMETER OutofPlace
12121212 Switch to create an out-of-place virtual machine restore.
12131213
1214- . PARAMETER DestHypervisorType
1215- Specify DestHypervisorType: vmware or hyperv for out-of-place restore.
1216- Note: DestHypervisorType defaults to 'vmare'. For hyperv out-of-place restore, this param must be provided on the command line.
1214+ . PARAMETER Requestbody
1215+ PSCustom object with request body which contains destination client and destination info or vmFileLevelRestoreOptions for out-of-place restore
12171216
12181217. PARAMETER Force
12191218 Switch to Force override of default 'WhatIf' confirmation behavior.
@@ -1228,7 +1227,25 @@ function Restore-CVVirtualMachine {
12281227 Restore-CVVirtualMachine -Name TESTVM12 -ClientName VSAQAVCDR.vsatest.commvault.com -SubclientName VMGroup1 -PowerOnAfterRestore -OverwriteExisting
12291228
12301229. EXAMPLE
1231- Restore-CVVirtualMachine -Name TESTVM12 -ClientName VSAQAVCDR.vsatest.commvault.com -SubclientName VMGroup1 -PowerOnAfterRestore -OverwriteExisting -OutofPlace
1230+ Restore-CVVirtualMachine -Name TESTVM12 -ClientName VSAQAVCDR.vsatest.commvault.com -SubclientName VMGroup1 -PowerOnAfterRestore -OverwriteExisting
1231+
1232+ . EXAMPLE
1233+ PS C:\> $requestbody = @'{
1234+ "destinationClient": {
1235+ "clientName": "testvsvc1.testlab.commvault.com_v2"
1236+ },
1237+ "destinationInfo": [
1238+ {
1239+ "vmware": {
1240+ "esxHost": "172.24.42.9",
1241+ "newName": "va-dummyVM2_DND",
1242+ "dataStore": "HDD_AutoDatastore",
1243+ "resourcePool": "/"
1244+ }
1245+ }
1246+ ]
1247+ } '@ | ConvertFrom-Json
1248+ Restore-CVVirtualMachine -Name va-dummyVM2_DND2 -outofPlace -Requestbody $requestbody -OverwriteExisting
12321249
12331250. OUTPUTS
12341251 Outputs [PSCustomObject] containing job submission result.
@@ -1273,148 +1290,21 @@ function Restore-CVVirtualMachine {
12731290 [Parameter (Mandatory = $False )]
12741291 [CVVSARestoreType ] $RestoreType = ' FullVirtualMachine' ,
12751292
1276- [Parameter (Mandatory = $False )]
1277- [CVVSAHyperVisorType ] $DestHypervisorType = ' vmware' ,
1278-
12791293 [Switch ] $OutofPlace ,
12801294 [Switch ] $PowerOnAfterRestore ,
12811295 [Switch ] $OverwriteExisting ,
1282- [Switch ] $Force
1283- )
1284-
1285- DynamicParam {
1286- $paramDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
1296+ [Switch ] $Force ,
12871297
1288- Set-StrictMode - Off
1298+ # Parameters required when OutOfPlace is enabled
1299+
1300+ [Parameter (Mandatory = $False )]
1301+ [System.Object ] $Requestbody
12891302
1290- if ($OutofPlace ) {
1291- if ($null -eq $RestoreType -or $RestoreType -eq ' FullVirtualMachine' ) { # default
1292- $destHypervisorAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1293- $destHypervisorAttr = New-Object System.Management.Automation.ParameterAttribute
1294- $destHypervisorAttr.Mandatory = $true
1295- $destHypervisorAttr.HelpMessage = ' restore destination hypervisor'
1296- $destHypervisorAttrColl.Add ($destHypervisorAttr )
1297- $destHypervisorParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' DestHypervisor' , [String ], $destHypervisorAttrColl )
1298- $paramDictionary.Add (' DestHypervisor' , $destHypervisorParam )
1299-
1300- if ($null -eq $DestHypervisorType -or $DestHypervisorType -eq ' vmware' ) { # default
1301- $destHostAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1302- $destHostAttr = New-Object System.Management.Automation.ParameterAttribute
1303- $destHostAttr.Mandatory = $true
1304- $destHostAttr.HelpMessage = ' out-of-place restore destination host'
1305- $destHostAttrColl.Add ($destHostAttr )
1306- $destHostParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' DestHost' , [String ], $destHostAttrColl )
1307- $paramDictionary.Add (' DestHost' , $destHostParam )
1308-
1309- $dataStoreAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1310- $dataStoreAttr = New-Object System.Management.Automation.ParameterAttribute
1311- $dataStoreAttr.Mandatory = $true
1312- $dataStoreAttr.HelpMessage = ' out-of-place restore datastore'
1313- $dataStoreAttrColl.Add ($dataStoreAttr )
1314- $dataStoreParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' DataStore' , [String ], $dataStoreAttrColl )
1315- $paramDictionary.Add (' DataStore' , $dataStoreParam )
1316-
1317- $resourcePoolAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1318- $resourcePoolAttr = New-Object System.Management.Automation.ParameterAttribute
1319- $resourcePoolAttr.Mandatory = $true
1320- $resourcePoolAttr.HelpMessage = ' out-of-place restore resource pool'
1321- $resourcePoolAttrColl.Add ($resourcePoolAttr )
1322- $resourcePoolAttrAllowEmpty = New-Object System.Management.Automation.AllowEmptyStringAttribute
1323- $resourcePoolAttrColl.Add ($resourcePoolAttrAllowEmpty )
1324- $resourcePoolParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' ResourcePool' , [String ], $resourcePoolAttrColl )
1325- $paramDictionary.Add (' ResourcePool' , $resourcePoolParam )
1326-
1327- $vmFolderAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1328- $vmFolderAttr = New-Object System.Management.Automation.ParameterAttribute
1329- $vmFolderAttr.Mandatory = $true
1330- $vmFolderAttr.HelpMessage = ' out-of-place restore VM folder path'
1331- $vmFolderAttrColl.Add ($vmFolderAttr )
1332- $vmFolderAttrAllowEmpty = New-Object System.Management.Automation.AllowEmptyStringAttribute
1333- $vmFolderAttrColl.Add ($vmFolderAttrAllowEmpty )
1334- $vmFolderParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' VMFolder' , [String ], $vmFolderAttrColl )
1335- $paramDictionary.Add (' VMFolder' , $vmFolderParam )
1336-
1337- $vmDisplayNameAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1338- $vmDisplayNameAttr = New-Object System.Management.Automation.ParameterAttribute
1339- $vmDisplayNameAttr.Mandatory = $true
1340- $vmDisplayNameAttr.HelpMessage = ' restore VM display name'
1341- $vmDisplayNameAttrColl.Add ($vmDisplayNameAttr )
1342- $vmDisplayNameParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' VMDisplayName' , [String ], $vmDisplayNameAttrColl )
1343- $paramDictionary.Add (' VMDisplayName' , $vmDisplayNameParam )
1344- }
1345- elseif ($DestHypervisorType -eq ' hyperv' ) {
1346- $destClientAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1347- $destClientAttr = New-Object System.Management.Automation.ParameterAttribute
1348- $destClientAttr.Mandatory = $true
1349- $destClientAttr.HelpMessage = ' out-of-place restore destination client'
1350- $destClientAttrColl.Add ($destClientAttr )
1351- $destClientParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' DestClient' , [String ], $destClientAttrColl )
1352- $paramDictionary.Add (' DestClient' , $destClientParam )
1353-
1354- $destFolderAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1355- $destFolderAttr = New-Object System.Management.Automation.ParameterAttribute
1356- $destFolderAttr.Mandatory = $true
1357- $destFolderAttr.HelpMessage = ' out-of-place restore destination folder'
1358- $destFolderAttrColl.Add ($destFolderAttr )
1359- $destFolderParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' DestFolder' , [String ], $destFolderAttrColl )
1360- $paramDictionary.Add (' DestFolder' , $destFolderParam )
1361-
1362- $regWithFailoverAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1363- $regWithFailoverAttr = New-Object System.Management.Automation.ParameterAttribute
1364- $regWithFailoverAttr.Mandatory = $true
1365- $regWithFailoverAttr.HelpMessage = ' register virtual machine with failover cluster? True or False'
1366- $regWithFailoverAttrColl.Add ($regWithFailoverAttr )
1367- $regWithFailoverParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' RegWithFailover' , [String ], $regWithFailoverAttrColl )
1368- $paramDictionary.Add (' RegWithFailover' , $regWithFailoverParam )
1369-
1370- $vmDisplayNameAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1371- $vmDisplayNameAttr = New-Object System.Management.Automation.ParameterAttribute
1372- $vmDisplayNameAttr.Mandatory = $true
1373- $vmDisplayNameAttr.HelpMessage = ' out-of-place restore VM display name'
1374- $vmDisplayNameAttrColl.Add ($vmDisplayNameAttr )
1375- $vmDisplayNameParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' VMDisplayName' , [String ], $vmDisplayNameAttrColl )
1376- $paramDictionary.Add (' VMDisplayName' , $vmDisplayNameParam )
1377- }
1378- }
1379- elseif ($RestoreType -eq ' VirtualMachineFiles' ) { # out-of-place restores for each virtual disk
1380- $sourcePathAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1381- $sourcePathAttr = New-Object System.Management.Automation.ParameterAttribute
1382- $sourcePathAttr.Mandatory = $true
1383- $sourcePathAttr.HelpMessage = ' source path of virtual machine files'
1384- $sourcePathAttrColl.Add ($sourcePathAttr )
1385- $sourcePathParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' SourcePath' , [String ], $sourcePathAttrColl )
1386- $paramDictionary.Add (' SourcePath' , $sourcePathParam )
1387-
1388- $destPathAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1389- $destPathAttr = New-Object System.Management.Automation.ParameterAttribute
1390- $destPathAttr.Mandatory = $true
1391- $destPathAttr.HelpMessage = ' destination path of virtual machine files'
1392- $destPathAttrColl.Add ($destPathAttr )
1393- $destPathParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' DestPath' , [String ], $destPathAttrColl )
1394- $paramDictionary.Add (' DestPath' , $destPathParam )
1395-
1396- $userNameAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1397- $userNameAttr = New-Object System.Management.Automation.ParameterAttribute
1398- $userNameAttr.Mandatory = $true
1399- $userNameAttr.HelpMessage = ' guest user name'
1400- $userNameAttrColl.Add ($userNameAttr )
1401- $userNameParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' UserName' , [String ], $userNameAttrColl )
1402- $paramDictionary.Add (' UserName' , $userNameParam )
1403-
1404- $passwordAttrColl = new-object System.Collections.ObjectModel.Collection[System.Attribute ]
1405- $passwordAttr = New-Object System.Management.Automation.ParameterAttribute
1406- $passwordAttr.Mandatory = $true
1407- $passwordAttr.HelpMessage = ' guest password'
1408- $passwordAttrColl.Add ($passwordAttr )
1409- $passwordParam = New-Object System.Management.Automation.RuntimeDefinedParameter(' Password' , [SecureString ], $passwordAttrColl )
1410- $paramDictionary.Add (' Password' , $passwordParam )
1411- }
1412- }
1303+ )
14131304
1414- Set-StrictMode - Version Latest
1305+
14151306
1416- return $paramDictionary
1417- }
1307+ # Set-StrictMode -Version Latest
14181308
14191309 begin { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : begin"
14201310
@@ -1452,7 +1342,7 @@ function Restore-CVVirtualMachine {
14521342 return
14531343 }
14541344 }
1455-
1345+
14561346 if (-not [String ]::IsNullOrEmpty($SubclientName )) {
14571347 $subclientObj = $ClientObject | Get-CVSubclient - Name $SubclientName
14581348 if ($null -eq $subclientObj ) {
@@ -1476,16 +1366,15 @@ function Restore-CVVirtualMachine {
14761366 Write-Information - InformationAction Continue - MessageData " INFO: $ ( $MyInvocation.MyCommand ) : virtual machine not found having name [$Name ]"
14771367 return
14781368 }
1479- }
1480-
1481- if ($vmObj.vmStatus -ne [CVVSAVMStatus ]::PROTECTED ) {
1482- if ( $vmObj .vmStatus -eq [CVVSAVMStatus ]::BACKED_UP_WITH_ERROR -and ( -not $Force .IsPresent )) {
1483- [ CVVSAVMStatus ] $status = $ vmObj.vmStatus
1484- Write-Information - InformationAction Continue - MessageData " INFO: $ ( $MyInvocation .MyCommand ) : virtual machine [ $ ( $vmObj .name ) ] has unsupported status [ $status ] "
1485- return
1369+
1370+ if ( $vmObj .vmStatus -ne [ CVVSAVMStatus ]::PROTECTED) {
1371+ if ($vmObj.vmStatus -eq [CVVSAVMStatus ]::BACKED_UP_WITH_ERROR -and ( -not $Force .IsPresent ) ) {
1372+ [CVVSAVMStatus ] $status = $vmObj .vmStatus
1373+ Write-Information - InformationAction Continue - MessageData " INFO: $ ( $MyInvocation .MyCommand ) : virtual machine [ $ ( $ vmObj.name ) ] has unsupported status [ $status ] "
1374+ return
1375+ }
14861376 }
14871377 }
1488-
14891378 $sessionObj.requestProps.endpoint = $sessionObj.requestProps.endpoint -creplace (' {vmGUID}' , $vmObj.strGUID )
14901379
14911380 <# request body parameters
@@ -1535,53 +1424,23 @@ function Restore-CVVirtualMachine {
15351424 if ($RestoreType -eq ' FullVirtualMachine' ) {
15361425 if ($OutofPlace ) {
15371426 $parameters.Add (' inPlaceRestore' , $False )
1538- $destinationClient = @ { }
1539- $destinationClient.Add (' clientName' , $PSBoundParameters.DestHypervisor )
1540- $parameters.Add (' destinationClient' , $destinationClient )
1541-
1542- $destinationInfo = @ { }
1543- [System.Collections.ArrayList ] $destnationInfo_arr = @ ()
1544- if ($DestHypervisorType -eq ' vmware' ) {
1545- $vmware = @ { }
1546- $vmware.Add (' esxHost' , $PSBoundParameters.DestHost )
1547- $vmware.Add (' dataStore' , $PSBoundParameters.Datastore )
1548- if (-not [String ]::IsNullOrEmpty($PSBoundParameters.ResourcePool )) {
1549- $vmware.Add (' resourcePool' , $PSBoundParameters.ResourcePool )
1550- }
1551- if (-not [String ]::IsNullOrEmpty($PSBoundParameters.VMFolder )) {
1552- $vmware.Add (' vmfolder' , $PSBoundParameters.VMFolder )
1553- }
1554- $vmware.Add (' newName' , $PSBoundParameters.VMDisplayName )
1555- $destinationInfo.Add (' vmware' , $vmware )
1556- }
1557- elseif ($DestHypervisorType -eq ' hyperv' ) {
1558- $hyperv = @ { }
1559- $hyperv.Add (' server' , $PSBoundParameters.DestClient )
1560- $hyperv.Add (' destinationPath' , $PSBoundParameters.DestFolder )
1561- $hyperv.Add (' registerwithFailover' , $PSBoundParameters.RegWithFailover )
1562- $hyperv.Add (' newName' , $PSBoundParameters.VMDisplayName )
1563- $destinationInfo.Add (' hyperv' , $hyperv )
1564- }
1565-
1566- $null = $destnationInfo_arr.Add ($destinationInfo )
1567- $parameters.Add (' destinationInfo' , $destnationInfo_arr )
1427+ $parameters.Add (' destinationClient' , $Requestbody.destinationClient )
1428+ $parameters.Add (' destinationInfo' , $Requestbody.destinationInfo )
15681429 }
15691430 else {
15701431 $parameters.Add (' inPlaceRestore' , $True )
15711432 }
15721433 }
1573- elseif ($RestoreType -eq ' VirtualMachineFiles' ) { # out-of-place restores for each virtual disk
1574- $vmFileLevelRestoreOptions = @ { }
1575- [System.Collections.ArrayList ] $sourcePath_arr = @ ()
1576- $null = $sourcePath_arr.Add ($PSBoundParameters.SourcePath )
1577- $vmFileLevelRestoreOptions.Add (' sourcePath' , $sourcePath_arr )
1578- $vmFileLevelRestoreOptions.Add (' destPath' , $PSBoundParameters.DestPath )
1579- $guestCredentials = @ { }
1580- $guestCredentials.Add (' userName' , $PSBoundParameters.UserName )
1581- $guestCredentials.Add (' password' , $PSBoundParameters.Password )
1582- $vmFileLevelRestoreOptions.Add (' guestCredentials' , $guestCredentials )
1583- $parameters.Add (' vmFileLevelRestoreOptions' , $vmFileLevelRestoreOptions )
1434+ elseif ($RestoreType -eq " VirtualMachineFiles" ){
1435+ if ($OutofPlace ) {
1436+ $parameters.Add (' inPlaceRestore' , $False )
1437+ }
1438+ else {
1439+ $parameters.Add (' inPlaceRestore' , $True )
1440+ }
1441+ $parameters.Add (' vmFileLevelRestoreOptions' , $Requestbody.vmFileLevelRestoreOptions )
15841442 }
1443+
15851444 else {
15861445 Write-Information - InformationAction Continue - MessageData " INFO: $ ( $MyInvocation.MyCommand ) : restore type [$RestoreType ] is not currently supported"
15871446 }
@@ -1592,7 +1451,6 @@ function Restore-CVVirtualMachine {
15921451 $payload.Add (' headerObject' , $headerObj )
15931452 $payload.Add (' body' , $body )
15941453 $validate = ' taskId'
1595-
15961454 if ($Force -or $PSCmdlet.ShouldProcess ($vmObj.name )) {
15971455 $response = Submit-CVRESTRequest $payload $validate
15981456 }
@@ -1607,6 +1465,7 @@ function Restore-CVVirtualMachine {
16071465 Write-Information - InformationAction Continue - MessageData " INFO: $ ( $MyInvocation.MyCommand ) : restore request declined for virtual machine [$ ( $vmObj.name ) ]"
16081466 }
16091467 }
1468+
16101469 catch {
16111470 throw $_
16121471 }
@@ -1615,7 +1474,6 @@ function Restore-CVVirtualMachine {
16151474 end { Write-Debug - Message " $ ( $MyInvocation.MyCommand ) : end"
16161475 }
16171476}
1618-
16191477
16201478function Add-CVVirtualMachine {
16211479<#
0 commit comments