ServerInfo.DiscoveryRule (DataSourceModuleType)

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
OutputTypeSystem.Discovery.Data

Member Modules:

ID Module Type TypeId RunAs 
DsServerInfoPs DataSource Microsoft.Windows.TimedPowerShell.DiscoveryProvider Default

Overrideable Parameters:

IDParameterTypeSelector
IntervalSecondsint$Config/IntervalSeconds$

Source Code:

<DataSourceModuleType ID="ServerInfo.DiscoveryRule" Accessibility="Internal" Batching="false">
<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="computerName" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DsServerInfoPs" TypeID="Windows!Microsoft.Windows.TimedPowerShell.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>DiscoverServerInfo.PS1</ScriptName>
<ScriptBody><Script>

# **********************************************************************************
# Script Name : DiscoverServerInfo
# Authored by : MphasiS Corporation
# Description : Discovers Lenovo Servers Properties
#
# Copyright (c) 2013 Lenovo Group. All rights reserved.
# Redistribution and use in source and binary forms, with or without modification,
# is not permitted without specific prior written permission from Lenovo.
# **********************************************************************************
param($sourceId,$managedEntityId,$computerName)

#--------------Inventory Logging--------------#
Function LogEntry($LogContent)
{
Try
{
$LoggingFlag_Reg = (New-Object -ComObject WScript.Shell).RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\LenovoPartnerPack\SCOMServer\Log")
if( $LoggingFlag_Reg -eq 1)
{
$SetLogging = $true
}
else
{
$SetLogging = $false
}
}
Catch
{
$SetLogging = $true
}

if ($SetLogging -eq $true)
{
$LogPath = ${Env:LENOVOPARTNERPACK_HOME} + "\Log"

if(![IO.Directory]::Exists($LogPath))
{
New-Item -ItemType directory -Path $LogPath
}

##$LogFileName = "ThinkServerPartnerPack_Inventory_"+ (Get-Date -Format "dd-MMM-yyyy")+".log"
$LogFileName = "ThinkServerPartnerPack_Inventory.log"
$LogFile = $LogPath + "\" + $LogFileName

$LogTime = Get-Date -Format "dd-MMM-yyyy HH:mm:ss"
$LogEntryContent = $LogTime + " : " + $LogContent

$LogEntryContent | Out-File $LogFile -Append -Force
}
}
#--------------Inventory Logging--------------#

$api = new-object -comObject 'MOM.ScriptAPI'
$discoveryServerInfo = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

$ErrorActionPreference = "Stop"

Function GetVMCountForOS2012R2
{
$NumberOfVMsOS2012R2 = 0
$ServerInfoVMCountOS2012R2 = Get-WmiObject -namespace "root\virtualization\v2" -Query $ServerInfo_VMCountQuery -ComputerName $computerName
foreach($ServerVM in $ServerInfoVMCountOS2012R2)
{
if ($ServerVM.ElementName -ne $OSVersion_Obj.CSName)
{
$NumberOfVMsOS2012R2 += 1
}
}
return $NumberOfVMsOS2012R2
}
Function GetVMCountForOSOld
{
$NumberOfVMsOSOld = 0
$ServerInfoVMCountOSOld = Get-WmiObject -namespace "root\virtualization" -Query $ServerInfo_VMCountQuery -ComputerName $computerName

foreach($ServerVM in $ServerInfoVMCountOSOld)
{
if ($ServerVM.ElementName -ne $OSVersion_Obj.CSName)
{
$NumberOfVMsOSOld += 1
}
}
return $NumberOfVMsOSOld
}

$OSVersion_Query = "select * from Win32_OperatingSystem"
$OSVersion_Obj = Get-WmiObject -namespace "root\cimv2" -Query $OSVersion_Query -ComputerName $computerName | select Caption, CSName

$ServerInfo_VMCountQuery = "SELECT * FROM Msvm_ComputerSystem"
$NumberOfVMs = 0
if ($OSVersion_Obj.Caption -like "*Microsoft Windows Server 2012 R2*")
{
try
{
$NumberOfVMs = GetVMCountForOS2012R2
}
catch
{
$NumberOfVMs = 0
}
}
elseif ( ($OSVersion_Obj.Caption -like "*Microsoft Windows Server 2008*") -or ($OSVersion_Obj -like "*Microsoft Windows Server 2012*"))
{
try
{
$NumberOfVMs = GetVMCountForOSOld
}
catch
{
$NumberOfVMs = 0
}
}
else
{
try
{
$VMsList = Get-VM -ComputerName $computerName
$NumberOfVMs = $VMsList.Count
}
catch
{
$NumberOfVMs = 0
}
}

$ComputerSystem_Query = "select * from Win32_ComputerSystem"
$ComputerSystemModules = Get-WmiObject -namespace "root\cimv2" -Query $ComputerSystem_Query

if($ComputerSystemModules.NumberOfLogicalProcessors -ge 0)
{
$NoOfThreads = $ComputerSystemModules.NumberOfLogicalProcessors
}
else
{
$NoOfThreads = "Not Available"
}
if($ComputerSystemModules.NumberOfProcessors -ge 0)
{
$NoOfProcessors = $ComputerSystemModules.NumberOfProcessors
}
else
{
$NoOfProcessors = "Not Available"
}

$Processor_Query = "select * from Win32_Processor"
$ProcessorModules = Get-WmiObject -namespace "root\cimv2" -Query $Processor_Query
$NoOfCores = 0
foreach ($ProcessorModule in $ProcessorModules)
{
if($ProcessorModule.NumberOfCores -ge 0)
{
$NoOfCores = $NoOfCores + $ProcessorModule.NumberOfCores
}
else
{
$NoOfCores = 0
}
}

$ServerInfo_Query3 = "Select * from Win32_OperatingSystem"
$ServerInfoModules3 = Get-WmiObject -namespace "root\cimv2" -Query $ServerInfo_Query3

foreach ($ServerInfoModule3 in $ServerInfoModules3)
{
if($ServerInfoModule3.Caption.Trim())
{
$HostOSVersion = $ServerInfoModule3.Caption
}
else
{
$HostOSVersion = "Not Available"
}
}

$ServerInfo_Query = "Select * from Win32_BIOS"
$ServerInfoModules = Get-WmiObject -namespace "root\cimv2" -Query $ServerInfo_Query

foreach ($ServerInfoModule in $ServerInfoModules)
{
if($ServerInfoModule.SMBIOSBIOSVersion.Trim())
{
$BIOSVersion = $ServerInfoModule.SMBIOSBIOSVersion
}
else
{
$BIOSVersion = "Not Available"
}

$instance = $discoveryServerInfo.CreateClassInstance("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']$")

$instance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $computerName)

$instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $computerName)

$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']/HostOSVersion$",$HostOSVersion)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']/NumberOfVMs$",$NumberOfVMs)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']/BIOSVersion$",$BIOSVersion)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']/NoOfThreads$",$NoOfThreads)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']/NoOfProcessors$",$NoOfProcessors)
$instance.AddProperty("$MPElement[Name='Lenovo.TMM.Server.MP.Inventory.ServerInfo.Class']/NoOfCores$",$NoOfCores)

LogEntry("Server Information for the host " + $computerName + " has been retrived")

$discoveryServerInfo.AddInstance($instance)
}

$discoveryServerInfo

</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>sourceID</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>managedEntityID</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>computerName</Name>
<Value>$Config/computerName$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>60</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DsServerInfoPs"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>