Add VmName validation and uniquiness checks
This commit is contained in:
@@ -50,10 +50,6 @@ function Invoke-ZertoFailover {
|
|||||||
if ( -not $vpgId) {
|
if ( -not $vpgId) {
|
||||||
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop
|
Write-Error "VPG: $vpgName Not Found. Please check the name and try again!" -ErrorAction Stop
|
||||||
}
|
}
|
||||||
$uniqueVmNames = $vmName | Select-Object -Unique
|
|
||||||
if ($uniqueVmNames.Count -ne $vmName.Count) {
|
|
||||||
Write-Error "The VM names you submitted contains a duplicate. Please check the values you submitted and try again. VALUES: $vmName" -ErrorAction Stop
|
|
||||||
}
|
|
||||||
$baseUri = "vpgs/{0}/failover" -f $vpgId
|
$baseUri = "vpgs/{0}/failover" -f $vpgId
|
||||||
$body = [ordered]@{}
|
$body = [ordered]@{}
|
||||||
# Setup Defaults
|
# Setup Defaults
|
||||||
@@ -65,13 +61,17 @@ function Invoke-ZertoFailover {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($PSBoundParameters.ContainsKey('vmName')) {
|
if ($PSBoundParameters.ContainsKey('vmName')) {
|
||||||
[array]$vmIdentifiers = @()
|
$vpgVmInformation = Get-ZertoProtectedVm -vpgName $vpgName
|
||||||
$vmIdentifiers = foreach ( $name in $vmName ) {
|
[System.Collections.ArrayList]$vmIdentifiers = @()
|
||||||
$result = $(Get-ZertoProtectedVm -vmName $name -vpgName $vpgName).vmIdentifier
|
foreach ( $name in $vmName ) {
|
||||||
if ($null -eq $result) {
|
$selectedVm = $vpgVmInformation | Where-Object {$_.VmName.toLower() -eq $name.toLower()}
|
||||||
Write-Error "VM: $name NOT found in VPG: $vpgName. Please check the names and try again." -ErrorAction Stop
|
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
|
||||||
}
|
}
|
||||||
$result
|
|
||||||
}
|
}
|
||||||
$body['VmIdentifiers'] = $vmIdentifiers
|
$body['VmIdentifiers'] = $vmIdentifiers
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user