if ([string]::IsNullOrEmpty($vcName))
{
LogErrorMessage "Error: vCenter Name is empty";
return;
}
if ([string]::IsNullOrEmpty($login) -or [string]::IsNullOrEmpty($pwd))
{
LogErrorMessage "Error: username or password are empty. Check Run As Profile 'Veeam VMware Direct ESX(i) Connection Account'.";
return;
}
if (-not ($mode -eq 0 -or $mode -eq 1))
{
LogErrorMessage "Error: Mode parameter should be 0 or 1";
return;
}
Function Convert-VCenterConnectionToDirectEsxConnection
{
Param ([string]$vCenterComputerName = $(throw "The vCenterComputerName parameter is required."), [System.Management.Automation.PSCredential] $credential)
if( $vmWareServer -eq $null ){
#$oAPI.logscriptevent($scriptName, $eventId, 1, "Error: No VMware Server with name '{0}' found" -f $vCenterComputerName);
throw ("No VMware Server with name '{0}' found" -f $vCenterComputerName);
}
if( $vmWareServer.VirtPlatform -ne "vCenter" ){
throw "Specified VMware Server VirtualizationPlatform property must be a vCenter";
}
$failover = ($force -eq 1);
if(!$failover)
{
echo "Updating connection status for vCenter Server $vCenterComputerName ...";
$testConn = Test-VMwareServerConnection $vmWareServer.ServerName -Quiet;
$failover = !$testConn.Passed;
}
if($vCenterMonitoredHosts -ne $null) {
echo "Disabling monitoring for vCenter Server $vCenterComputerName";
Disable-Monitoring -VMwareServer $vmWareServer -Include $vCenterMonitoredHosts -Force;
}
$oAPI.logscriptevent($scriptName, $eventId, 0, "vCenter Server $vCenterComputerName is not available and will be failed over to direct ESX(i) host connections.");
}
else {
#### changed error description for Force vCenter connection failover task
echo "VMware vCenter Server $vcName will not be failed over to direct host connection. No ESX host connections avalable or connection has been already failed over to direct host connections";
$oAPI.logscriptevent($scriptName, $eventId, 0, "VMware vCenter Server $vcName will not be failed over to direct host connection. No ESX host connections avalable.");
}
}
else
{
echo "No action required - VMware vCenter Server $vcName is available";
$oAPI.logscriptevent($scriptName, $eventId, 0, "No action required - VMware vCenter Server $vcName is available");
}
}
Function Convert-DirectEsxConnectionToVCenterConnection
{
Param ([string]$vCenterComputerName = $(throw "The vCenterComputerName parameter is required."))
if($esxHosts -ne $null) { #### added for Force vCenter connection failover task
foreach ($esx in $esxHosts) {
echo ("Removing ESX host {0} from monitoring" -f $esx);
}
Remove-VMwareServer $esxHosts;
}
else
{
#### added for Force vCenter connection failover task
echo "No failed over direct ESX host connections avalable or connection has been already failed back to a healthy vCenter connection";
$oAPI.logscriptevent($scriptName, $eventId, 0, "No failed over direct ESX host connections avalable or connection has been already failed back to a healthy vCenter connection");
}
}
catch [Exception] {
$errorMsg = $_.Exception.Message;
echo "Error removing host from monitoring: $errorMsg";
}
if($vCenterHosts -ne $null) {
echo "Enabling monitoring of vCenter Server $vCenterComputerName";
Enable-Monitoring -VMwareServer $vmWareServer -Include $vCenterHosts -Force;
$oAPI.logscriptevent($scriptName, $eventId, 0, "vCenter Server $vCenterComputerName is now available and will be failed back from direct ESX(i) host connections.");
}
}
else
{
echo "VMware vCenter Server $vcName is unavailable, failback operation cannot be performed, Veeam MP will continue to monitor Hosts via direct connections";
}