Microsoft.SystemCenter.VirtualMachineManager.PRO.V2.Recovery.RecoveryScriptModule (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
InputTypeSystem.BaseData
OutputTypeMicrosoft.Windows.SerializedObjectData

Member Modules:

ID Module Type TypeId RunAs 
PSWA WriteAction Microsoft.Windows.PowerShellWriteAction Default

Source Code:

<WriteActionModuleType ID="Microsoft.SystemCenter.VirtualMachineManager.PRO.V2.Recovery.RecoveryScriptModule" Accessibility="Public">
<Configuration>
<IncludeSchemaTypes>
<SchemaType>Windows!Microsoft.Windows.PowerShellSchema</SchemaType>
</IncludeSchemaTypes>
<!-- PROTip Params -->
<xsd:element name="EventDescription" type="xsd:string"/>
<!-- Script send by user for remediation -->
<xsd:element name="ScriptBody" type="xsd:string"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<ModuleImplementation>
<Composite>
<MemberModules>
<WriteAction TypeID="Windows!Microsoft.Windows.PowerShellWriteAction" ID="PSWA">
<ScriptName>PRORecoveryScript</ScriptName>
<ScriptBody><Script>
Param($eventContent, $domain, $username, $pass);
$eventContent = $eventContent.Trim().Split('|');

$evt = New-Object System.Diagnostics.Eventlog("Application");
$evt.Source = "Microsoft.SystemCenter.VirtualMachineManager.PRO";
$infoevent = [System.Diagnostics.EventLogEntryType]::Error;

if($eventContent.Count -Lt 4)
{
$evt.WriteEntry('Invalid number of parameters are passed to the script.', $infoevent, 100);
return;
}

$error.Clear();
$hostName = $eventContent[$eventContent.Count - 6].Trim();
$VMMServer = $eventContent[$eventContent.Count - 5].Trim();
$PROTipID = $eventContent[$eventContent.Count - 4].Trim();
$PROTipID = $PROTipID.replace("{", $null);
$PROTipID = $PROTipID.replace("}", $null);

$scriptParameters = $eventContent[$eventContent.Count - 1].Trim();

$cred = $null;
if ($domain -AND $username -AND $pass)
{
#Append domain to get domain\username
$domainUser = $domain + "\" + $username;

#Create Cred object
$securePass = ConvertTo-SecureString -AsPlainText $pass -force
$cred = New-Object System.Management.Automation.PSCredential $domainUser, $securePass;

}

####### Remote Session
if ($cred -ne $null)
{
$session = $null;
Try
{
$session = New-PSSession -ComputerName $VMMServer -Authentication Default -Credential $cred;
if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $infoevent, 25931);
return;
}
else
{
Invoke-Command -Session $session -ArgumentList $VMMServer, $hostName, $PROTipID -ScriptBlock {$modulePath = get-itemproperty -path "hklm:\software\microsoft\microsoft system center virtual machine manager administrator console\Setup"; Import-Module ($modulePath.InstallPath + "bin\psModules\virtualmachinemanagercore\virtualmachinemanagercore.psd1"); $VMMServer = Get-SCVMMServer -ComputerName $args[0]; $hostName = $args[1]; $PROTipID = $args[2]} ;
if ($error.Count -ne 0)
{
$evt.WriteEntry($error, $infoevent, 25932);
return;
}

Invoke-Command -Session $session -ArgumentList $scriptParameters -ScriptBlock {$Config/ScriptBody$;};

}
}
Finally
{
if ($session -ne $null)
{
Remove-PSSession $session;
}
}
}


</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>eventContent</Name>
<Value>$Config/EventDescription$</Value>
</Parameter>
<Parameter>
<Name>domain</Name>
<Value>$RunAs[Name="Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Domain$</Value>
</Parameter>
<Parameter>
<Name>username</Name>
<Value>$RunAs[Name="Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/UserName$</Value>
</Parameter>
<Parameter>
<Name>pass</Name>
<Value>$RunAs[Name="Microsoft.SystemCenter.VirtualMachineManager.2012.VMMServerConnectionRunAsProfile"]/Password$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<StrictErrorHandling>true</StrictErrorHandling>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="PSWA"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>Windows!Microsoft.Windows.SerializedObjectData</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>