function LogInfo($logMessage, $doLog = $isDebug) {
if ($doLog) {
[Diagnostics.EventLog]::WriteEntry("ITImpact Recovery", "Info: " + $logMessage);
}
}
function LogError($logMessage) {
[Diagnostics.EventLog]::WriteEntry("ITImpact Recovery", "Error: " + $logMessage);
}
if ($eventContent -eq $null) {
eventcreate /T Error /ID 100 /L APPLICATION /SO VMMPro /D 'No parameters are passed to the script.';
return;
}
#Parse the contents and put the parameters into an array
$eventContentArray = $eventContent.Split(':');
#Check to ensure all of the expected parameters have been passed
if ($eventContentArray.Count -lt 5) {
eventcreate /T Error /ID 100 /L APPLICATION /SO VMMPro /D 'Invalid number of parameters is passed to the script.';
return;
}
# We have a VM host on the machine, so we Set Host into Maintenance Mode and we start the ProTip
Set-PROTip -PROTipId $protipId -TipStatus Running;
LogInfo("Setting PROTip status to running");
# Find all VMs on the host that have not been excluded from PRO
foreach ($cVM in $hostObjVMs){
if($cVM.ExcludeFromPRO -ne $true) {
$candidateVMs = $candidateVMs + $cVM;
}
}
# Checking if QuickMigration is possible and getting all VMHosts available (in same group)
$isQuickMigration = $false;
$hostList = @();
$vmHostGrout = @();
$allhosts = Get-VMHost -VMHostGroup $vmHost.VMHostGroup;
# Stop if no hosts to migrate to
if (($hostList -eq $null) -or ($hostList.Count -eq 0)) {
FailNoHostToMigrateTo $protipId $vmHostName;
$vmmServer.Disconnect();
return;
}
# Stop if VMs are Excluded from PRO level actions.
if(($candidateVMs.Count -eq 0) -or ($candidateVMs -eq $null)){
FailNoVMToMigrate $protipId $vmHostName;
$vmmServer.Disconnect();
return;
}
LogInfo("Setting PROTip status to resolved");
#only setting the PROTip to resolved once all Vms has been migrated
Set-PROTip -PROTipId $protipId -TipStatus Resolved;
$vmmServer.Disconnect();
}
#Calling the main method
Main;</Script></ScriptBody>
<SnapIns>
<SnapIn>Microsoft.SystemCenter.VirtualMachineManager</SnapIn>
</SnapIns>
<Parameters>
<Parameter>
<Name>eventContent</Name>
<Value>$Config/EventDescription$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>90</TimeoutSeconds>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Recovery"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.BaseData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>