Microsoft.SystemCenter.VirtualMachineManager.Pro.BaseAction (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
BaseAction WriteAction System.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelector
EventDescriptionstring$Config/EventDescription$

Source Code:

<WriteActionModuleType ID="Microsoft.SystemCenter.VirtualMachineManager.Pro.BaseAction" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="EventDescription" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="EventDescription" Selector="$Config/EventDescription$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="BaseAction" TypeID="System!System.CommandExecuter">
<ApplicationName>%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>
-Command " $eventContent = '$Config/EventDescription$'; $eventContent = $eventContent.Split(':'); if($eventContent.Count -Lt 4) { eventcreate /T Error /ID 100 /L APPLICATION /SO VmmPro /D 'Invalid number of parameters are passed to the script.'; return; } $hostName = $eventContent[$eventContent.Count - 4].Replace('\n','').Trim(); $serverName = $eventContent[$eventContent.Count - 3].Trim(); $ProtipId = $eventContent[$eventContent.Count - 2].Trim(); $vmErrorCode = $eventContent[$eventContent.Count - 1].Trim()[0]; $debugMessage = 'Starting PRO Tip execution. Parameters passed: Host Name: ' + $hostName + ', Server Name: ' + $serverName + ', Tip Id : ' + $ProtipId + ', VM Error Code: ' + $vmErrorCode; eventcreate /T Information /ID 100 /L APPLICATION /SO VmmPro /D $debugMessage; $Error.Clear(); add-pssnapin -name Microsoft.SystemCenter.VirtualMachineManager; if( $Error.Count -ne 0 ) { eventcreate /T Error /ID 111 /L APPLICATION /SO VmmPro /D $Error[0]; return; } function new-array { $args } function FailGenericError { Set-PROTip -PROTipId $args[0] -LastError $args[1] -TipStatus Failed; } function FailHostNotFound { $params = new-array '$MPElement[Name='ProMessage.SourceHostNotfound']$' $args[1]; Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; } function FailNoVMFound { switch($args[1]) { 1 { $params = new-array '$MPElement[Name='ProMessage.NoVMFound.CPU']$' $args[2]; } 2 { $params = new-array '$MPElement[Name='ProMessage.NoVMFound.Memory']$' $args[2]; } } Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; } function FailNoVMToMigrate { $params = new-array '$MPElement[Name='ProMessage.NoVMFound.MigrationEligible']$' $args[1]; Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; } function FailNoHostToMigrateTo { $params = new-array '$MPElement[Name='ProMessage.TargetHostNotfound']$' $args[1]; Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; } function FailInvalidErrorCode { $params = new-array '$MPElement[Name='ProMessage.InvalidErrorCode']$'; Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; } function Main { $Error.Clear(); $serverObj = get-vmmserver -computerName $serverName; if( $Error.Count -ne 0) { FailGenericError $ProtipId $Error[0]; return; } Set-PROTip -PROTipId $ProtipId -TipStatus Running; $hostobj = get-vmhost -computername $hostName -vmmserver $serverObj; if( $hostobj -eq $null ) { FailHostNotFound $ProtipId $hostName; return; } $allvms = $hostobj | Get-VM; if(($hostobj.VMs -eq $null) -or ($hostobj.VMs.Count -eq 0)) { FailNoVMFound $ProtipId $vmErrorCode $hostName; return; } $candidateVMs = @(); foreach( $cVM in $hostobj.VMs | where { $_.Status -eq 'Running'} | where { $_.ExcludeFromPRO -ne $TRUE} ) { $candidateVMs = $candidateVMs + $cVM; } if($candidateVMs.Count -eq 0) { FailNoVMToMigrate $ProtipId $hostName; return; } switch($vmErrorCode) { 1 { foreach( $tVM in ($candidateVMs | sort PerfCPUUtilization -Descending) ) { $selectedVM = $tVM; break; } if( $selectedVM.PerfCPUUtilization -eq 0 ) { FailNoVMFound $ProtipId $vmErrorCode $hostName; return; } } 2 { foreach( $tVM in ($candidateVMs | sort Memory -Descending) ) { $selectedVM = $tVM; break; } if( $selectedVM.Memory -eq 0 ){ FailNoVMFound $ProtipId $vmErrorCode $hostName; return; } } default { FailInvalidErrorCode $ProtipId; return; } } $isQuickMigration = $false; $hostList = @(); $allhosts = Get-VMHost -VMHostGroup $hostobj.VMHostGroup; if(($hostobj.HostCluster -ne $null ) -and ($hostobj.HostCluster.Nodes.Count -ne 1)){ foreach ( $tmpHost in $hostobj.HostCluster.Nodes ) { if( $tmpHost.Name -ne $hostobj.Name ) { $hostList = $hostList + $tmpHost; $isQuickMigration = $true; } } } else { foreach ( $tmpHost in $hostobj.VMHostGroup.Hosts ) { if( $tmpHost.Name -ne $hostobj.Name ) { $hostList = $hostList + $tmpHost; } } } if(($hostList -eq $null) -or ($hostList.Count -eq 0)) { FailNoHostToMigrateTo $ProtipId $hostName; return; } $vmHostRatings = @(); $vmHostRatings = $vmHostRatings + ( @(Get-VMHostRating -VM $selectedVM -VMHost $hostList -IsMigration -UseDefaultPath) | Sort-Object -property Rating -descending | where { $_.Rating -ne 0 } ); if ( $vmHostRatings.Count -eq $null) { FailNoHostToMigrateTo $ProtipId $hostName; return; } $selectedVMHost = $hostList | where { ($_.Name -eq $vmHostRatings[0].VMHost.Name) }; if($selectedVMHost -eq $null) { FailNoHostToMigrateTo $ProtipId $hostName; return; } $Error.Clear(); if($isQuickMigration) { Move-VM -VM $selectedVM -VMHost $selectedVMHost -PROTipId $ProtipId; } else { $defaultPaths = @($selectedVMHost.VMPaths | where { $_.StartsWith($vmHostRatings[0].PreferredVolume) -eq 1 }); if( $defaultPaths[0] -eq $null) { FailNoHostToMigrateTo $ProtipId $hostName; return; } Move-VM -VM $selectedVM -VMHost $selectedVMHost -Path $defaultPaths[0] -PROTipId $ProtipId; } if( $Error.Count -ne 0) { FailGenericError $ProtipId $Error[0]; return; } Set-PROTip -PROTipId $ProtipId -TipStatus Resolved; } Main; "
</CommandLine>
<TimeoutSeconds>86400</TimeoutSeconds>
<RequireOutput>false</RequireOutput>
<Files/>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="BaseAction"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>