Community.VMware.DataSource.HostState (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsDefault
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
Scheduler DataSource System.SimpleScheduler Default
HostStateProbe ProbeAction Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe Default
FilterHost ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$
SyncTimestring$Config/SyncTime$
TimeoutSecondsint$Config/TimeoutSeconds$

Source Code:

<DataSourceModuleType Accessibility="Public" ID="Community.VMware.DataSource.HostState">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="IntervalSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="SyncTime" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="TimeoutSeconds" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="vCenterServerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" minOccurs="1" name="HostId" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation>
<Composite>
<MemberModules>
<DataSource TypeID="System!System.SimpleScheduler" ID="Scheduler">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime>$Config/SyncTime$</SyncTime>
</DataSource>
<ProbeAction TypeID="Windows!Microsoft.Windows.PowerShellPropertyBagTriggerOnlyProbe" ID="HostStateProbe">
<ScriptName>Community.VMware.Probe.HostState.ps1</ScriptName>
<ScriptBody><Script>param($vCenterServerName)

$ScriptName = 'Community.VMware.Probe.HostState.ps1'
$api = new-object -comObject 'MOM.ScriptAPI'

Function LogScriptEvent {
Param (

#0 = Informational
#1 = Error
#2 = Warning
[parameter(Mandatory=$true)]
[ValidateRange(0,2)]
[int]$EventLevel
,

[parameter(Mandatory=$true)]
[string]$Message
)

$api.LogScriptEvent($ScriptName,1985,$EventLevel,$Message)
}

Function DefaultErrorLogging {
LogScriptEvent -EventLevel 1 -Message ("$_`rType:$($_.Exception.GetType().FullName)`r$($_.InvocationInfo.PositionMessage)`rReceivedParam:`rvCenterServerName:$vCenterServerName")
}

Try {
Add-PSSnapin VMware.VimAutomation.Core
} Catch {
Start-Sleep -Seconds 10
Try {
Add-PSSnapin VMware.VimAutomation.Core
} Catch {
DefaultErrorLogging
Exit
}
}

Try {
$connection = Connect-VIServer -Server $vCenterServerName -Force:$true -NotDefault
} Catch {
Start-Sleep -Seconds 10
Try {
$connection = Connect-VIServer -Server $vCenterServerName -Force:$true -NotDefault
} Catch {
DefaultErrorLogging
Exit
}
}

&lt;#
If ($connection.IsConnected -ne $True){
LogScriptEvent 0 ("Unable to connect to vCenter server " + $vCenterServerName)
exit
}
#&gt;

Try {$VMhosts = Get-View -Server $connection -ViewType HostSystem -Property Runtime | Select Runtime,MoRef}
Catch {DefaultErrorLogging}

&lt;#
If (!$VMhosts){
LogScriptEvent 0 ("No hosts found in vCenter server " + $vCenterServerName)
Try {Disconnect-VIServer -Server $connection -Confirm:$false}
Catch {DefaultErrorLogging}
exit
}
#&gt;

ForEach ($VMhost in $VMhosts){

$bag = $api.CreatePropertyBag()
$bag.AddValue('HostId', [string]$VMhost.MoRef)
$bag.AddValue('vCenterServerName', $vCenterServerName)
$bag.AddValue('PowerState',[string]$VMhost.Runtime.PowerState)
$bag
}

Try {Disconnect-VIServer -Server $connection -Confirm:$false}
Catch {DefaultErrorLogging}</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>vCenterServerName</Name>
<Value>$Config/vCenterServerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</ProbeAction>
<ConditionDetection TypeID="System!System.ExpressionFilter" ID="FilterHost">
<Expression>
<And>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='HostId']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/HostId$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='vCenterServerName']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">$Config/vCenterServerName$</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</And>
</Expression>
</ConditionDetection>
</MemberModules>
<Composition>
<Node ID="FilterHost">
<Node ID="HostStateProbe">
<Node ID="Scheduler"/>
</Node>
</Node>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>