Validate identifiers are present
This commit is contained in:
@@ -24,18 +24,35 @@ function Start-ZertoCloneVpg {
|
||||
|
||||
begin {
|
||||
$baseUri = "vpgs"
|
||||
|
||||
$vpgInfo = Get-ZertoVpg -name $vpgName
|
||||
if ( -not $vpgInfo ) {
|
||||
Write-Error "VPG: $vpgName could not be found. Please check the name and try again."
|
||||
}
|
||||
$vpgIdentifier = $vpgInfo.vpgIdentifier
|
||||
if ( $PSBoundParameters.ContainsKey('datastoreName') ) {
|
||||
$recoverysiteIdentifier = $vpgInfo.recoverysite.identifier
|
||||
$recoverySiteDatastores = Get-ZertoVirtualizationSite -siteIdentifier $recoverysiteIdentifier -datastores
|
||||
$datastoreIdentifier = $($recoverySiteDatastores | Where-Object {$_.datastoreName -like $datastoreName}).DatastoreIdentifier
|
||||
if ( -not $datastoreIdentifier ) {
|
||||
Write-Error "Datastore: $datastoreName is not a valid datastore. Please check the name and try again." -ErrorAction Stop
|
||||
}
|
||||
}
|
||||
if ( $PSBoundParameters.ContainsKey('vmName') ) {
|
||||
$vmIdentifiers = @()
|
||||
$vmIdentifiers = foreach ( $name in $vmName ) {
|
||||
$(Get-ZertoProtectedVm -vmName $name).vmIdentifier
|
||||
$vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
|
||||
[System.Collections.ArrayList]$vmIdentifiers = @()
|
||||
foreach ( $name in $vmName ) {
|
||||
$selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()}
|
||||
if ($null -eq $selectedVm) {
|
||||
Write-Error "VM: $name NOT found in VPG $vpgName. Check the name and try again." -ErrorAction Stop
|
||||
} elseif ($vmIdentifiers.Contains($selectedVm.vmIdentifier.toString())) {
|
||||
Write-Error "VM: $($selectedVm.VmName) specified more than once. Please check parameters and try again." -ErrorAction Stop
|
||||
} else {
|
||||
$vmIdentifiers.Add($selectedVm.vmIdentifier.toString()) | Out-Null
|
||||
}
|
||||
}
|
||||
$body['VmIdentifiers'] = $vmIdentifiers
|
||||
if ($checkpointIdentifier) {
|
||||
$body['CheckpointIdentifier'] = $checkpointIdentifier
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user