Veeam Virtualizations Extensions VMware vSphere Host connection test module
Veeam.Virt.Extensions.VMware.PSWriteAction.TestVMwareConnections (WriteActionModuleType)
Element properties: Member Modules:
Overrideable Parameters:
Source Code: <WriteActionModuleType ID="Veeam.Virt.Extensions.VMware.PSWriteAction.TestVMwareConnections" Accessibility="Internal" RunAs="SC!Microsoft.SystemCenter.PrivilegedMonitoringAccount">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="TimeoutSeconds" type="xsd:int"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction ID="RunScript" TypeID="Windows!Microsoft.Windows.PowerShellWriteAction">
<ScriptName>TestVMwareConnection.ps1</ScriptName>
<ScriptBody><Script> param($username, $pass);
$eventId = "993";
$momApi = New-Object -ComObject "MOM.ScriptAPI";
$severityWarning = 2;
$severityError = 1;
$severitySuccess = 0;
Function Import-ModuleIfNot
{
$moduleName = "Psves";
$moduleLoaded = $false;
$Error.Clear();
Import-Module $moduleName -ErrorAction:SilentlyContinue;
if ($Error.Count -ne 0)
{
$rkey = "HKLM:\SYSTEM\CurrentControlSet\Services\VeeamVE";
$rvalName = "ImagePath";
$rval = Get-ItemProperty -path:$rkey -name:$rvalName -ErrorAction:SilentlyContinue;
$modulePath = "";
if ($rval -ne $null)
{
$dbPath = $rval.ImagePath;
$vesPath = $dbPath.Replace('"', '');
$vesPath = $vesPath.Remove($vesPath.LastIndexOf("\"));
$vesPath = $vesPath.Remove($vesPath.LastIndexOf("\"));
$modulePath = $vesPath + "\VE Shell\Modules";
}
$Error.Clear();
Import-Module "$modulePath\$moduleName" -ErrorAction:SilentlyContinue;
}
if ($Error.Count -eq 0)
{
$moduleInf = Get-Module | ? {$_.Name -eq $moduleName};
if ($moduleInf -ne $null)
{
$moduleLoaded = $true;
}
}
return $moduleLoaded;
}
$moduleImported = Import-ModuleIfNot;
if ($moduleImported) {
$rkey = "HKLM:\SOFTWARE\Veeam\Veeam Virtualization Extensions for VMware\Manager";
$rvalName = "Port";
$rval = Get-ItemProperty -path:$rkey -name:$rvalName -ErrorAction:SilentlyContinue;
$port = "8084";
if ($rval -ne $null)
{
$port = $rval.Port;
}
Start-VEShellClient -ServerPort $port -ServerName localhost;
$password = $pass | ConvertTo-SecureString -asPlainText -Force;
$credential = New-Object System.Management.Automation.PSCredential($username, $password)
$eventText = New-Object System.Text.StringBuilder;
$eventText.AppendLine('One or more hosts cannot be contacted using credentials specified in the "Veeam VMware Direct ESX(i) Connection Account" RunAs Profile which is being used during the vCenter connection failover. Please check that the specified account can connect to the following hosts:') | Out-Null;
$servArr = @();
$error.Clear();
Get-VMwareServer -ErrorAction SilentlyContinue | ? {$_.VirtPlatform -eq 'vCenter'} | % {
$monHosts = $_.Topology | Where { $_.Type -eq "Host" -and $_.Monitored };
foreach ($mh in $monHosts) {
$servArr+=$mh.name;
}
}
if ($error.Count -gt 0) {
$momApi.LogScriptEvent("TestVMwareConnection.ps1", 992, $severityError, $error[0].Exception.Message);
}
else {
$error.Clear();
$testres = Test-VMwareServerAvailable $servArr -Credential $credential -ErrorAction SilentlyContinue;
if ($error.Count -gt 0) {
$momApi.LogScriptEvent("TestVMwareConnection.ps1", 992, $severityError, $error[0].Exception.Message);
}
else {
[bool] $haveFails = $false;
$hostCounter = 0;
foreach ($res in $testres) {
if ($res.Status -ne [Veeam.Psves.VMwareServerConnectionStatus]::OperationSuccess) {
$eventText.AppendLine("$($res.ComputerName)") | Out-Null;
$haveFails = $true;
$hostCounter++;
}
}
if ($haveFails) {
if ($hostCounter -gt 100) {
$momApi.LogScriptEvent("TestVMwareConnection.ps1", $eventId, $severityError, 'For more than 100 hosts Virtualization Extensions Service was unable to verify credentials specified in the "Veeam VMware Direct ESX(i) Connection Account" RunAs Profile which is being used during the vCenter connection failover. vCenter connection failover cannot work without properly configured RunAs Profile.');
}
else {
$momApi.LogScriptEvent("TestVMwareConnection.ps1", $eventId, $severityError, $eventText.ToString());
}
}
else {
$momApi.LogScriptEvent("TestVMwareConnection.ps1", $eventId, $severitySuccess, 'The account specified in "Veeam VMware Direct ESX(i) Connection Account" RunAs profile has been successfully validated on all vSphere Hosts.');
}
}
}
}
else {
$momApi.LogScriptEvent("TestVMwareConnection.ps1", 992, $severityError, "Veeam Virtualization Extensions PowerShell module (PSVES) could not be imported. Check that Virtualization Extension Service has been correctly installed and has a valid license");
}</Script> </ScriptBody>
<Parameters>
<Parameter>
<Name>username</Name>
<Value>$RunAs[Name="VeeamVEBaseDisc!Veeam.Virt.Extensions.VMware.ESXMonitoringAccount"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>pass</Name>
<Value>$RunAs[Name="VeeamVEBaseDisc!Veeam.Virt.Extensions.VMware.ESXMonitoringAccount"]/Password$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="RunScript"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>