Fujitsu PRIMERGY Discovery Rule for Windows Servers

Fujitsu.Servers.PRIMERGY.Windows.PSServerDiscoveryRule (Discovery)

Discovery Rule for Fujitsu PRIMERGY Windows Servers, ServerView Agents Software

Knowledge Base article:

Summary

This discovery rule instantiates Fujitsu PRIMERGY Windows Servers, ServerView Agents and ServerView WMI Providers.

Element properties:

TargetFujitsu.Servers.PRIMERGY.WindowsSeed.Server
EnabledTrue
Frequency14400
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
PSDS DataSource Fujitsu.Servers.PRIMERGY.Windows.PSServerDiscoveryDataSource Default

Source Code:

<Discovery ID="Fujitsu.Servers.PRIMERGY.Windows.PSServerDiscoveryRule" Enabled="true" Target="FTSWS!Fujitsu.Servers.PRIMERGY.WindowsSeed.Server" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.CollectionsHost">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.BXServer">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.CXServer">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.RXServer">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.SXServer">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.TXServer">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.XXServer">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.PQPartition">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
<Property TypeID="Windows!Microsoft.Windows.Computer" PropertyID="PrincipalName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="Model"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="SerialNumber"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.Server" PropertyID="NetworkName"/>
<Property TypeID="FTSLIB!Fujitsu.ServerView.System" PropertyID="OperatingSystem"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="IPAddress"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="ChassisModel"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Manufacturer"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="TotalDisk"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="PhysicalMemory"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="Cabinets"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="BMC_DNS"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="SystemFirmware"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.Server" PropertyID="MonitoringAgents"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.Processors">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.Memory">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.Fans">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.TemperatureSensors">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.VoltageSensors">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.PowerSupplies">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.ServerStorage">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.ServerNetworks">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.ManagementController">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.PowerConsumption">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisks">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrives">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
<DiscoveryClass TypeID="Fujitsu.Servers.PRIMERGY.Windows.OtherComponents">
<Property TypeID="FTSLIB!Fujitsu.ServerView.HealthCollection" PropertyID="ServerName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="NetworkName"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddrIPv4"/>
<Property TypeID="Fujitsu.Servers.PRIMERGY.Windows.HealthCollection" PropertyID="BMCAddr"/>
</DiscoveryClass>
</DiscoveryTypes>
<DataSource ID="PSDS" TypeID="Fujitsu.Servers.PRIMERGY.Windows.PSServerDiscoveryDataSource">
<!-- Note: default every 4 hours (14400) -->
<IntervalSeconds>14400</IntervalSeconds>
<ScriptName>PRIMERGYServerDiscoveryComplete.ps1</ScriptName>
<ScriptBody><Script>#===================================================================
#===================================================================
#
# FUJITSU Limited
# Copyright (C) FUJITSU Limited 2008 - 2019
#
#===================================================================
#===================================================================
#-------------------------------------------------------------------
# PRIMERGYServerDiscoveryComplete.ps1 $SourceId $ManagedEntityId $PrincipalName $TargetComputer $ManagementGroup [$DebugLevel] [$DebugTest]
#
# Summary:
# Discover Fujitsu PRIMERGY Windows Server.
#-------------------------------------------------------------------

param (
[string]$SourceId,
[string]$ManagedEntityId,
[string]$PrincipalName,
[string]$TargetComputer,
[string]$ManagementGroup,
[string]$DbgLevel,
[string]$DbgTest
)

Set-Variable -Name MPScript -Option Constant -Value "PRIMERGYServerDiscoveryComplete.ps1"
Set-Variable -Name LogFileName -Option Constant -Value "PRIMERGYServerDiscoveryTrace"
$script:TargetComputer = $TargetComputer
$script:MGMGroup = $ManagementGroup

#script runs inside MP
$script:insideMP = $True

# check PowerShell version
$PSVersion = $PSVersionTable.PSVersion
if ($PSVersion.Major -lt 2) {
Debug-Out "PowerShellVersion V$PSVersion is too low! Use at least V2.0!", $DBG_INFO
exit 0
}

#-------------------------------------------------------------------

function Main
{
Initialize-Logging $SEC_ServerDiscovery ""

Debug-Out "Server Discovery Version is: *** $($script:MPVersion) ***" $DBG_INFO
Debug-Out "Server Discovery Management Group is: *** $($script:MGMGroup) ***" $DBG_INFO

$WMIVersion = $PSVersionTable.BuildVersion
$OSVersion = [System.Environment]::OSVersion.Version
$OSName = Get-OSProperty "ProductName"
$OSEdition = Get-OSProperty "EditionID"
Debug-Out "Running on PowerShell $PSVersion, WMI $WMIVersion, OS $OSVersion." $DBG_INFO
Debug-Out "Running on '$OSName', Edition '$OSEdition.'" $DBG_INFO

if (("$OSEdition".Contains("Nano") -eq $True)) { $script:isNano = $True }
Debug-Out "Running on Nano Server = $($script:isNano)" $DBG_INFO

Initialize-LogIniFile

$SourceType = 0
if ($script:insideMP -eq $True) {
try {
$oAPI = New-Object -ComObject "MOM.ScriptAPI" -ErrorAction Stop
Debug-Out "CreateDiscoveryData($SourceType, '$SourceId', '$ManagedEntityId')" $DBG_SCOM
$oDiscoveryData = $oAPI.CreateDiscoveryData($SourceType, "$SourceId", "$ManagedEntityId")
$oDiscoveryEmptyData = $oAPI.CreateDiscoveryData($SourceType, "$SourceId", "$ManagedEntityId")
} catch {
Debug-Out "Could not generate 'MOM.ScriptAPI' object. We are not inside an MP, set insideMP = False" $DBG_INFO
$script:insideMP = $False
}
}

if ($script:isNano -eq $True) {
Debug-Out "*******" $DBG_INFO
Debug-Out "******* We are running on Nano Server. Quit." $DBG_INFO
Debug-Out "*******" $DBG_INFO
if ($script:insideMP -eq $True) {
$oDiscoveryEmptyData
}
exit 0
}

# check where we get monitored from
$aGroupName = ""
try {
$agentGroupsKey = "HKLM:\Software\Microsoft\Microsoft Operations Manager\3.0\Agent Management Groups"
if (Test-Path -Path $agentGroupsKey) {
$agentGroups = Get-ChildItem $agentGroupsKey
foreach ($aGroup in $agentGroups) {
if ($aGroupName -ne "") { $aGroupName += ", " }
$aLen = "$aGroup".Length
$aLIndex = "$aGroup".LastIndexOf("\") + 1
$aGroupName += "$aGroup".Substring($aLIndex,$aLen-$aLIndex)
}
Debug-Out "Found $($agentGroups.Count) Monitoring Agent Management Group(s): $aGroupName" $DBG_INFO
} else {
Debug-Out "Did not find Monitoring Agents Group key in Registry." $DBG_INFO
}
} catch {
Debug-Out "Could not check where we get monitored from." $DBG_INFO
}

# check whether we are monitored with more than one MP
try {
$agentMPPath = "C:\Program Files\Microsoft Monitoring Agent\Agent\Health Service State\Management Packs"
$winMpList = [System.Collections.ArrayList]@()
if (Test-Path -Path $agentMPPath) {
$mpGroup = Get-ChildItem $agentMPPath
$lastMpID = ""
$mpList = [System.Collections.ArrayList]@()
$mpVersionList = [System.Collections.ArrayList]@()
foreach ($mp in $mpGroup) {
if ("$mp" -Match "Fujitsu.Servers.PRIMERGY.Windows") {
[xml]$mpXml = Get-Content "$agentMPPath\$mp"
$mpID = $mpXml.ManagementPack.Manifest.Identity.ID
$mpVersion = $mpXml.ManagementPack.Manifest.Identity.Version
#Debug-Out "Found MP '$mp', Version '$mpVersion'" $DBG_SCOM
if ($lastMpID -eq $mpID) {
$i = $mpList.Add($mp)
$i = $mpVersionList.Add($mpVersion)
#Debug-Out "Server is already monitored with MP '$mpID'." $DBG_SCOM
} else {
$mpList = [System.Collections.ArrayList]@()
$mpVersionList = [System.Collections.ArrayList]@()
$i = $mpList.Add($mp)
$i = $mpVersionList.Add($mpVersion)
$i = $winMpList.Add(@($mpID, $mpList, $mpVersionList))
}
$lastMpID = $mpID
}
}
}

$mpMessage = ""
foreach ($mp in $winMpList) {
if ($mp[1].Count -gt 1) {
$mpMessage += "This Server is monitored by $($mp[1].Count) MPs of Type '$($mp[0])'`r`n"
$i = 0
foreach ($smp in $mp[1]) {
$mpMessage += " Management Pack: '$($mp[1][$i])', Version '$($mp[2][$i])'`r`n"
$i++
}
}
}
if ($mpMessage -ne "") {
$mpMessage += "The following Monitoring Agent Management Group(s) monitor this server: $aGroupName"
Write-ScriptEvent $oAPI 212 $INFORMATIONAL_EVENT $mpMessage
}
} catch {
Debug-Out "Could not check MPs." $DBG_SCOM
}

# SVAgents
#-----------------------------------
$SVAgentVersion = "N/A"

$SVAgentsPath = Get-SVAgentsPath
Debug-Out "SV-Agents Path: $SVAgentsPath" $DBG_INFO

# We are assuming that the service runs.
# Real check is requesting SV Agent Version.
$script:SVAgentRunning = $True

if ([string]::IsNullOrEmpty($SVAgentsPath)) {
Debug-Out "#############" $DBG_INFO
Debug-Out "############# ServerView Agent is not installed on PRIMERGY Server $($script:TargetComputer)!" $DBG_INFO
Debug-Out "############# Quit." $DBG_INFO
Debug-Out "#############" $DBG_INFO
exit 0
}
$script:SVAgentRunning = Get-SVAgentsRunning
Debug-Out "ServerView Agent Service found running = $($script:SVAgentRunning)" $DBG_INFO

if ($script:SVAgentRunning -eq $False) {
Debug-Out "**** ServerView Agent is not running on PRIMERGY Server $($script:TargetComputer). *** Quit. ****" $DBG_INFO
if ($script:insideMP -eq $True) {
# make sure we do not discard existing Discovery Data within SCOM
# tell SCOM that this stuff is invalid
$oDiscoveryEmptyData.IsSnapshot = $False
$oDiscoveryEmptyData
}
exit 0
} else {
$script:oSwitch = New-Object -comObject "Rswitch.Rswitch.1"
#*** give a hint to agents, who accesses them (in case of DEBUG / trace)
$script:oSwitch.ClientName = $script:SVISCOMName

# request SV Agent version to check whether SCCI is possible
# Note: SV Agentless service seems to indicate SV Agents running but does not support SCCI
$MonitoringAgents = "N/A"
$Status = $script:oSwitch.ScciQuery(0x0C00, 0xA806, 0, -1, 0, [REF]$SVAgentVersion, 0)
if ($Status -ne 0) {
Debug-Out "oSwitch: No Data for opCode=0x0C00 opCodeExt=0xA806 objIndex=0 cabID=-1" $DBG_DESC
Debug-Out "#############" $DBG_INFO
Debug-Out "############# ServerView SCCI not supported on $($script:TargetComputer)!" $DBG_INFO
Debug-Out "#############" $DBG_INFO
$script:oSwitch = $Null
$script:SVASRunning = $True
} else {
Debug-Out "oSwitch: opCode=0x0C00 opCodeExt=0xA806 objIndex=0 cabID=-1 -&gt; scciValue = '$SVAgentVersion'" $DBG_DESC
if ($SVAgentVersion.Length -gt 6 ) { $SVAgentVersion = $SVAgentVersion.Substring(0, 7) }
Debug-Out "SV-Agent Version: $SVAgentVersion" $DBG_INFO
$MonitoringAgents = "$SVAgentName V$SVAgentVersion"
if (($SVAgentVersion.Length -eq 0) -or ($SVAgentVersion -lt $SVAGENTVERSION_MIN)) {
Write-ScriptEvent $oAPI 211 $WARNING_EVENT "ServerView Agent Version V$SVAgentVersion too old! Use at least V$SVAGENTVERSION_MIN!"
}
}
}

if ($script:SVASRunning -eq $True) {
Debug-Out "**** ServerView Agentless Service is running. *** Quit. ****" $DBG_INFO
if ($script:insideMP -eq $True) {
$oDiscoveryEmptyData
}
exit 0
}

$script:CIMProvider = $False
if (($SVAgentVersion -ne "N/A") -and (($SVAgentVersion -gt $SVCIMVERSION_MIN) -and ($OSVersion -gt "6.0"))) { $script:CIMProvider = $True }
Debug-Out "This system has CIMProvider = $script:CIMProvider" $DBG_INFO

# check whether the script was forced to CIM/SCCI
if (($script:DebugTest -eq "SCCI") -or ($script:DebugTest -eq "CIM")) {
if ($script:DebugTest -eq "SCCI") { $script:CIMProvider = $False }
if ($script:DebugTest -eq "CIM") { $script:CIMProvider = $True }
Debug-Out "This system has CIMProvider = $script:CIMProvider" $DBG_INFO
}

# check currently simulated commands
$DbgSimList = Get-ScciData 0xF009 0 0 -1
if ("$DbgSimList" -ne "") {
$DbgSimList = $DbgSimList.Substring(0, $DbgSimList.Length - 1)
$DbgSimList = $DbgSimList.Replace("OC=", " OC=")
Debug-Out "Simulations:" $DBG_INFO
Debug-Out "$DbgSimList" $DBG_INFO
}

if ($script:CIMProvider -eq $False) { $SVNamespace = $cimv2NS }
if ($script:CIMProvider -eq $True) { $SVNamespace = $svsNS }

# check whether Agents or Providers can supply data
if ($SVAgentVersion -gt $SVAGENTVERSION_MIN) {
$CheckSVOverallState = Get-SVOverallState
Debug-Out "Check ServerView Overall State: $CheckSVOverallState" $DBG_INFO
if ($CheckSVOverallState -eq $False) {
if ($script:CIMProvider -eq $True) {
Debug-Out "**** ServerView CIM providers cannot supply data at this time. *** Quit. ****" $DBG_INFO
} else {
Debug-Out "**** ServerView Agents cannot supply data at this time. *** Quit. ****" $DBG_INFO
}
if ($script:insideMP -eq $True) {
# make sure we do not discard existing Discovery Data within SCOM
# tell SCOM that this stuff is invalid
$oDiscoveryEmptyData.IsSnapshot = $False
$oDiscoveryEmptyData
}
exit 0
}
} else {
$CheckSVOverallState = $True
}

$SVRaidVersion = Get-SVRaidVersion
Debug-Out "SV RAID Version: $SVRaidVersion" $DBG_INFO

$script:CIMRaidProvider = $False
if ($SVAgentVersion -ge $CIMRAID_AGENTS_MIN -and $SVRaidVersion -ge $CIMRAID_SVRAID_MIN) { $script:CIMRaidProvider = $True }
Debug-Out "This system has CIM Raid Provider = $script:CIMRaidProvider" $DBG_INFO

# check whether the script was forced to CIM/SCCI
if (($script:DebugTest -eq "SCCI") -or ($script:DebugTest -eq "CIM")) {
if ($script:DebugTest -eq "SCCI") { $script:CIMRaidProvider = $False }
if ($script:DebugTest -eq "CIM") { $script:CIMRaidProvider = $True }
Debug-Out "This system has CIM Raid Provider = $script:CIMRaidProvider" $DBG_INFO
}

# Main Cabinet ID
if ($script:SVAgentRunning -eq $True) {
$script:Cabinet = -1
$script:Cabinet = Get-ScciData 0xE204 0 0 -1
Debug-Out "Main Cabinet ID = $($script:Cabinet)" $DBG_INFO
}


# Determine Cabinet Number(s) for SCCI
#---------------------------------------------------------------
if ($script:SVAgentRunning -eq $True) {
$cabName = Get-ScciData 0x0C00 0x0108 0 $script:Cabinet
$Cabinets = "Main: $($script:Cabinet) ($cabName)"

$script:CabinetArray[0] = $script:Cabinet
$cabData = Get-ScciData 0x0220 0 0 $script:Cabinet

if ($Null -ne $cabData) {
$index = 1
$Cabinets = "$Cabinets, Extension: "
if ($cabData -is [system.array]) {
for ($i=0; $i -lt $cabData.Length; $i++) {
$script:CabinetArray[$index] = "$('{0:X2}' -f $cabData[$i+1])$('{0:X2}' -f $cabData[$i])"
$script:CabinetArray[$index] = [convert]::ToInt32($script:CabinetArray[$index], 16)
$i++
$index++
}
Debug-Out " cabString[]: $cabString" $DBG_INFO
} else {
if ($cabData -gt 0xFFFF) {
$script:CabinetArray[$index] = $cabData -band 0x0000FFFF
$index ++
#$script:CabinetArray[$index] = $cabData -shr 16 # PS v3.0
$script:CabinetArray[$index] = [convert]::ToInt32([math]::Floor($cabData * [math]::Pow(2,-16)))
} else {
$script:CabinetArray[$index] = $cabData
}
$index ++
}

$index = 0
foreach ($cabData in $script:CabinetArray) {
if ($index -gt 0 -and $Null -ne $cabData) {
$cabName = Get-ScciData 0x0C00 0x0108 0 $cabData
Debug-Out "CabinetID $($index): $cabData ($cabName)" $DBG_INFO
$Cabinets = "$Cabinets, $cabData ($cabName)"
}
$index ++
}
}
}
Debug-Out "Cabinets: [$Cabinets]" $DBG_INFO


# ***** start Server Discovery ****
#-------------------------------------------------
$SavedModelName = Get-PYServerData "ModelName"
$SavedManufacturer = Get-PYServerData "Manufacturer"

$ManufacturerShort = ""
$Manufacturer = ""
$ModelName = ""
$ChassisModel = ""
$SerialNumber = ""
$totalMemory = 0

# do not create an error message here (last arg = 'False') in case this is not a FUJITSU system!
if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYChassis"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
# Check that we really get our cabinet (relevant for BX and CX)
if ([convert]::ToInt32("0x$($objItem.Tag)", 16) -eq [convert]::ToInt32("$Cabinet", 10)) {
$Manufacturer = $objItem.Manufacturer
$ModelName = $objItem.Model
$ChassisModel = $objItem.Name
$SerialNumber = $objItem.SerialNumber
}
Debug-Out "\$($SVNamespace):$SVAgentClass.Tag: $($objItem.Tag)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.Manufacturer: $($objItem.Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.Model: $($objItem.Model)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.Name: $($objItem.Name)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.SerialNumber: $($objItem.SerialNumber)" $DBG_DESC
}
}
} else {
if ($script:SVAgentRunning -eq $True) {
$Manufacturer = Get-ScciData 0xC00 0x150A 0x0 $script:Cabinet
$ModelName = Get-ScciData 0xC00 0x0608 0x0 $script:Cabinet
$SerialNumber = Get-ScciData 0xC00 0x0600 0x0 $script:Cabinet
$ChassisModel = Get-ScciData 0xC00 0x0108 0x0 $script:Cabinet
}
}

# if Agents are not running but the Seed Discovery found that this is a Fujitsu server
# (we would not be here otherwise), let's try to find out who we are
# start with PYServerData
if ($script:SVAgentRunning -eq $False) {
$Manufacturer = $SavedManufacturer
$ModelName = $SavedModelName
$ChassisModel = Get-PYServerData "ChassisModel"
$SerialNumber = Get-PYServerData "SerialNumber"
}

$ModelNamePRIMERGYModelGroup = $ModelName
$ModelNamePRIMERGY = $ModelName
$ChassisModelShort = $ModelName
if ($ModelName.Length -gt 10 ) { $ModelNamePRIMERGYModelGroup = $ModelName.Substring(0, 11) }
if ($ModelName.Length -gt 7 ) { $ModelNamePRIMERGY = $ModelName.Substring(0, 8) }
if ($ChassisModel.Length -gt 6 ) { $ChassisModelShort = $ChassisModel.Substring(0, 7).ToUpper() }
$ChassisID = "N/A"

Debug-Out "Manufacturer: [$Manufacturer]" $DBG_INFO
Debug-Out "Model Name: [$ModelName]" $DBG_INFO
Debug-Out "Chassis Model: [$ChassisModel]" $DBG_INFO
Debug-Out "Chassis Model Short: [$ChassisModelShort]" $DBG_INFO
Debug-Out "Serial Number: [$SerialNumber]" $DBG_INFO
Debug-Out "Model Name PRIMERGY: [$ModelNamePRIMERGY]" $DBG_INFO
Debug-Out "PRIMERGY Model Group: [$ModelNamePRIMERGYModelGroup]" $DBG_INFO


# For BX servers find out MMB Address
$MMBIP = ""
if ($ModelNamePRIMERGYModelGroup -eq "PRIMERGY BX") {
$SVAgentClass = "SVS_PGYIPProtocolEndpoint"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass WHERE SystemCreationClassName='SVS_PGYChassisController'" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ("$MMBIP" -ne "") { break; }
Debug-Out "MMB IPv4 Address: $($objItem.IPv4Address)" $DBG_INFO
Debug-Out "\$($cimv2NS):$SVAgentClass.SystemCreationClassName: $($objItem.SystemCreationClassName)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.SystemName: $($objItem.SystemName)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.IPv4Address: $($objItem.IPv4Address)" $DBG_DESC
$MMBIP = "$($MMBIP)https://$($objItem.IPv4Address)"
}
}
Debug-Out "MMB IP(s): [$MMBIP]" $DBG_INFO
}


# Calculate the total memory size using CIM_PhysicalMemory
#-------------------------------------------------
# totalMemory must be taken from CIM_PhysicalMemory, as Win32_ComputerSystem gives 'memory avail to OS'
$SVAgentClass = "CIM_PhysicalMemory"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS

$totalMemory = 0
if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
Debug-Out "Memory size (module): $($objItem.Capacity)" $DBG_INFO
Debug-Out "\$($cimv2NS):$SVAgentClass.Capacity: $($objItem.Capacity)" $DBG_DESC
if ($objItem.Capacity -gt 0) { $totalMemory = $totalMemory + $objItem.Capacity }
}
}

Debug-Out "Memory size (overall): $totalMemory" $DBG_INFO
$totalMemoryUnit = ConvertTo-MatchingUnit($totalMemory)
Debug-Out "Memory size (overall): $totalMemoryUnit" $DBG_INFO


#*** Get ServerName from Win32_ComputerSystem
#-------------------------------------------------
$SVAgentClass = "Win32_ComputerSystem"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS
$FTSServerName = $($CimData.Name)
Debug-Out "\$($cimv2NS):$SVAgentClass.Name: $($CimData.Name)" $DBG_DESC
Debug-Out "ServerName: [$FTSServerName]" $DBG_INFO


# Get OS Name from Win32_OperatingSystem
#-------------------------------------------------
$SVAgentClass = "Win32_OperatingSystem"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS
if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
$OSName = $objItem.Caption
$OSVersion = $objItem.Version
$OSServerName = $objItem.CSName
Debug-Out "\$($cimv2NS):$SVAgentClass.Caption: $($CimData.Caption)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.Version: $($CimData.Version)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.CSName: $($CimData.CSName)" $DBG_DESC
}
}
Debug-Out "OSName: $OSName" $DBG_INFO
Debug-Out "OSVersion: $OSVersion" $DBG_INFO
Debug-Out "OSServerName: $OSServerName" $DBG_INFO


# Check the PRIMERGY model using Win32_ComputerSystemProduct
#--------------------------------------------------------
# In case we did not get Manufacturer and ModelName from FTS classes, try Win32_ComputerSystemProduct
if ($Manufacturer -eq "" -or $ModelName -eq "") {
$SVAgentClass = "Win32_ComputerSystemProduct"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2Ns

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ($Manufacturer -eq "") {
Debug-Out "\$($cimv2NS):$SVAgentClass.Vendor: $($objItem.Vendor)" $DBG_DESC
$Manufacturer = $objItem.Vendor
Debug-Out "Manufacturer: [$Manufacturer]" $DBG_INFO
}

if ($ModelName -eq "") {
Debug-Out "\$($cimv2NS):$SVAgentClass.Vendor: $($objItem.Name)" $DBG_DESC
$ModelName = $objItem.Name
if ($ModelName.Length -gt 10 ) { $ModelNamePRIMERGYModelGroup = $ModelName.Substring(0, 11) }
if ($ModelName.Length -gt 7 ) { $ModelNamePRIMERGY = $ModelName.Substring(0, 8) }
Debug-Out "ModelName: [$ModelName]" $DBG_INFO
Debug-Out "ModelNamePRIMERGY: [$ModelNamePRIMERGY]" $DBG_INFO
Debug-Out "ModelNamePRIMERGYModelGroup: [$ModelNamePRIMERGYModelGroup]" $DBG_INFO
}

if ($ChassisModel -eq "") {
$ChassisModel = "Unknown"
}
}
}
}

#*** use saved data if we got no identification
if ($SavedModelName -ne "" -and $SavedModelName -ne $ModelName) {
Debug-Out "Use saved PY Server Data:" $DBG_INFO
$ModelName = $SavedModelName
$Manufacturer = $SavedManufacturer
$ChassisModel = Get-PYServerData "ChassisModel"
$ChassisModelShort = $ChassisModel
if ($ModelName.Length -gt 7 ) { $ModelNamePRIMERGY = $ModelName.Substring(0, 8).ToUpper() }
if ($ModelName.Length -gt 10 ) { $ModelNamePRIMERGYModelGroup = $ModelName.Substring(0, 11).ToUpper() }
if ($ChassisModelShort.Length -gt 6 ) { $ChassisModelShort = $ChassisModelShort.Substring(0, 7).ToUpper() }

Debug-Out "ModelName: [$ModelName]" $DBG_INFO
Debug-Out "ModelNamePRIMERGY: [$ModelNamePRIMERGY]" $DBG_INFO
Debug-Out "ModelNamePRIMERGYModelGroup: [$ModelNamePRIMERGYModelGroup]" $DBG_INFO
Debug-Out "Chassis Model: [$ChassisModel]" $DBG_INFO
Debug-Out "Manufacturer: [$Manufacturer]" $DBG_INFO
}

$ManufacturerShort = $Manufacturer
if ($ManufacturerShort.Length -gt 7 ) { $ManufacturerShort = $ManufacturerShort.Substring(0, 7).ToUpper() }
Debug-Out "ManufacturerShort: [$ManufacturerShort]" $DBG_INFO

$serverClass = ""
if (($ManufacturerShort -eq "FUJITSU") -or ($ManufacturerShort -eq "FSC")) {
Debug-Out "ModelNamePRIMERGY: [$ModelNamePRIMERGY]" $DBG_INFO
if ($ModelNamePRIMERGY -eq "PRIMERGY") {
Debug-Out "ModelNamePRIMERGYModelGroup: [$ModelNamePRIMERGYModelGroup]" $DBG_INFO
if (($ModelNamePRIMERGYModelGroup -eq "PRIMERGY TX") -or ($ChassisModelShort -eq "EC100F") -or ($ChassisModelShort -eq "EC200F")) {
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: TX-Model" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.TXServer']$"
} elseif ($ModelNamePRIMERGYModelGroup -eq "PRIMERGY CX") {
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: CX-Model" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.CXServer']$"
} elseif ($ModelNamePRIMERGYModelGroup -eq "PRIMERGY RX") {
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: RX-Model" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RXServer']$"
} elseif ($ModelNamePRIMERGYModelGroup -eq "PRIMERGY SX") {
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: SX-Model" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SXServer']$"
} elseif ($ModelNamePRIMERGYModelGroup -eq "PRIMERGY BX") {
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: BX-Model" $DBG_INFO
$ChassisID = "$ChassisModel.$SerialNumber"
Debug-Out "ChassisID: $ChassisID" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.BXServer']$"
} else {
# Not an uptodate PRIMERGY model
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: Other PRIMERGY Model" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.XXServer']$"
}
} elseif ($ModelNamePRIMERGY -eq "PRIMEQUE") {
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: PRIMEQUEST Partition" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PQPartition']$"
} else {
#Not a modern PRIMERGY model
Debug-Out "$($script:TargetComputer) / $ModelName inserted in ModelNamePRIMERGYModelGroup: Other PRIMERGY Model" $DBG_INFO
$serverClass = "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.XXServer']$"
}

#*** save ModelName
if (($SavedModelName.Length -eq 0) -and ($ModelName -ne "")) {
Save-PYServerData "ModelName" $ModelName
Save-PYServerData "ChassisModel" $ChassisModel
Save-PYServerData "Manufacturer" $Manufacturer
}
Save-PYServerData "OSVersion" "$OSVersion"
Save-PYServerData "PSVersion" "$PSVersion"

# assign default values if not set
if ($ModelName -eq "") { $ModelName = "Unknown" }
if ($ChassisModel -eq "") { $ChassisModel = "Unknown" }
if ($ChassisID -eq "") { $ChassisID = "N/A" }
if ($Manufacturer -eq "") { $Manufacturer = "FUJITSU" }

Debug-Out "PrincipalName = $PrincipalName" $DBG_INFO
Debug-Out "FTSServerName = $FTSServerName" $DBG_INFO
Debug-Out "TargetComputer = $($script:TargetComputer)" $DBG_INFO
Debug-Out "ModelName = $ModelName" $DBG_INFO
Debug-Out "ChassisModel = $ChassisModel" $DBG_INFO

# Check PrincipalName (from SCOM) against FTSServerName (from hardware) to eliminate cluster ressources
#*** does not work with: PrincipalName = "."
if ($PrincipalName.Length -gt 2) {
#*** cut off domain extension, if it exists
$PName = $PrincipalName
if ($PrincipalName.Contains(".")) { $PName = @($PrincipalName -Split "\.")[0] }
$FName = $FTSServerName
if ($FTSServerName.Contains(".")) { $FName = @($FTSServerName -Split "\.")[0] }
Debug-Out "Principal-base = $PName" $DBG_INFO
Debug-Out "FTSServer-base = $FName" $DBG_INFO

if ($PName -ne $FName) {
#*** FTSServerName is different from PrincipalName!
#*** This is the case e.g. for a cluster resource = NO SERVER!
Debug-Out "#############" $DBG_INFO
Debug-Out "############# PrincipalName (base) &lt;&gt; FTSServerName (base)!" $DBG_INFO
Debug-Out "############# (base = checked without domain name extension)" $DBG_INFO
Debug-Out "#############" $DBG_INFO
Debug-Out "############# This is no SERVER to monitor!" $DBG_INFO
Debug-Out "#############" $DBG_INFO
Debug-Out "############# return empty DISCOVERY data and quit script." $DBG_INFO
Debug-Out "#############" $DBG_INFO
if ($script:insideMP -eq $True) {
$oDiscoveryEmptyData
}
exit 0
} else {
Debug-Out "PrincipalName (base) = FTSServerName (base). This is no cluster ressource." $DBG_INFO
}
} else {
Debug-Out "#############" $DBG_INFO
Debug-Out "############# WARNING:" $DBG_INFO
Debug-Out "#############" $DBG_INFO
Debug-Out "############# 'insideMP = true' and PrincipalName has two or less characters??????" $DBG_INFO
Debug-Out "#############" $DBG_INFO
}
} else {
Debug-Out "**** Not a system of FUJITSU. *** Quit. ****" $DBG_INFO
if ($script:insideMP -eq $True) {
$oDiscoveryEmptyData
}
exit 0
}

# check whether a customer wants to skip Monitoring
$noMon = Get-PYServerData "NoMonitor"
if (($Null -ne $noMon) -and ($noMon.Length -ne 0)) {
if ($noMon.ToLower() -eq "true") {
Debug-Out "**** Found noMonitor flag in Registry. *** Quit. ****" $DBG_INFO
if ($script:insideMP -eq $True) {
$oDiscoveryEmptyData
}
exit 0
}
}

if ($serverClass.Length -eq 0) {
if ($script:insideMP -eq $True) {
$oDiscoveryEmptyData
}
exit 0 # not a PRIMERGY Server of Fujitsu
}


# get server IP adress(es)
#---------------------------------------
$IPAddress = ""

$SVAgentClass = "Win32_NetworkAdapterConfiguration"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass WHERE MACAddress &gt; ''" -Namespace $cimv2NS

$index = 0
if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ($objItem.IPAddress -is [system.array]) {
if ($IPAddress -ne "") {
$IPAddress = "$IPAddress, "
}
$strComponentValue = "IP Address(es) $($index): "

for ($i = 0; $i -lt $objItem.IPAddress.Count; $i++) {
if ($i -eq 0) {
if ($objItem.IPAddress[$i] -ne "") {
$IPAddress = "$IPAddress$($objItem.IPAddress[$i])"
$strComponentValue = "$strComponentValue$($objItem.IPAddress[$i])"
}
}
if ($i -eq 1) {
if ($objItem.IPAddress[$i] -ne "") {
$IPAddress = "$IPAddress/$($objItem.IPAddress[$i])"
$strComponentValue = "$strComponentValue / $($objItem.IPAddress[$i])"
}
}
Debug-Out "$strComponentValue" $DBG_INFO
}
$index ++
}
}
}
Debug-Out "IP Address: $IPAddress" $DBG_INFO


# calculate total local disk space
#---------------------------------------
$TotalLocalDisk = 0
$TotalLocalDiskNo = 0

$SVAgentClass = "Win32_DiskDrive"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ("$($objItem.MediaType)".Contains("Removable")) {
Debug-Out "Skipping removable media '$($objItem.Caption)'." $DBG_INFO
} elseif ("$($objItem.MediaType)".Contains("External")) {
Debug-Out "Skipping external media '$($objItem.Caption)'." $DBG_INFO
} else {
Debug-Out "Disk $($objItem.Caption), Type $($objItem.MediaType), Size: $($objItem.Size)" $DBG_INFO
if (($objItem.Size -ne 0) -or ($objItem.Size.Length -ne 0)) {
$TotalLocalDisk = $TotalLocalDisk + $objItem.Size
}
$TotalLocalDisk = $TotalLocalDisk + $objItem.Size
$TotalLocalDiskNo ++
}
Debug-Out "\$($cimv2NS):$SVAgentClass.Caption: $($objItem.Caption)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.MediaType: $($objItem.MediaType)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.Size: $($objItem.Size)" $DBG_DESC
}
}

$TotalLocalDiskUnit = ConvertTo-MatchingUnit($TotalLocalDisk)
Debug-Out "TotalLocalDiskSize: $TotalLocalDiskUnit" $DBG_INFO
Debug-Out "TotalLocalDiskNo: $TotalLocalDiskNo" $DBG_INFO


# get BMC IP addresses
#---------------------------------------
if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYComputerSystem"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ($objItem.AdminUrlIPv4 -ne "") { $BMCIPv4Addr = $objItem.AdminUrlIPv4 }
if ($objItem.AdminUrlIPv6 -ne "") { $BMCIPv6Addr = $objItem.AdminUrlIPv6 }
if ($objItem.AdminUrlDNS -ne "") { $iRMCDNSName = $objItem.AdminUrlDNS }
Debug-Out "\$($SVNamespace):$SVAgentClass.AdminUrlIPv4: $($objItem.AdminUrlIPv4)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.AdminUrlIPv6: $($objItem.AdminUrlIPv6)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.AdminUrlDNS: $($objItem.AdminUrlDNS)" $DBG_DESC
}
}
} else {
if ($script:SVAgentRunning -eq $True) {
# check for iRMC
$iRMCName = Get-ScciData 0xC00 0x508 0 $script:Cabinet
if ("$iRMCName".ToLower() -match "irmc") {
$BMCIPv4Addr = Get-ScciData 0xE205 0 0 $script:Cabinet
$BMCIPv6Addr = Get-ScciData 0xE205 1 0 $script:Cabinet
$iRMCDNSName = Get-iRMCDNSName
}
}
}
if ([string]::IsNullOrEmpty($BMCIPv4Addr)) { $BMCIPv4Addr = "N/A" }
if ([string]::IsNullOrEmpty($BMCIPv6Addr)) { $BMCIPv6Addr = "N/A" }
if ($iRMCDNSName -eq "N/A") { $iRMCDNSName = $BMCIPv4Addr }

Debug-Out "BMC Address IPv4: $BMCIPv4Addr" $DBG_INFO
Debug-Out "BMC Address IPv6: $BMCIPv6Addr" $DBG_INFO
Debug-Out "BMC DNS name: $iRMCDNSName" $DBG_INFO

# get the System Firmware information
#-------------------------------------------
$SystemFirmware = "N/A"

$SVAgentClass = "Win32_BIOS"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS
Debug-Out "\$($cimv2NS):$SVAgentClass.SMBIOSBIOSVersion: $($CimData.SMBIOSBIOSVersion)" $DBG_DESC
$SystemFirmware = $($CimData.SMBIOSBIOSVersion).Trim()
Debug-Out "SystemFirmware: $SystemFirmware" $DBG_INFO

#ServerView RAID
#-------------------------------------------
$RaidManager = "N/A"
if ($SVRaidVersion -ne "") {
$RaidManager = "$SVRaidName V$SVRaidVersion"
}

#-------------------------------------------
if ($script:insideMP -eq $True) {
if ((-not [string]::IsNullOrEmpty($SVAgentName)) -and (-not [string]::IsNullOrEmpty($WMIVersion))) {
Debug-Out "Create Server instance: $ChassisModel" $DBG_SCOM
$oServer = $oDiscoveryData.CreateClassInstance($serverClass)
Add-ObjectData $oServer $FTSServerName $PrincipalName
Add-MPElement $oServer "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.Server']/NetworkName$" $script:TargetComputer "MPElement[Name='FTSLIB!Fujitsu.ServerView.Server']/NetworkName"
Add-MPElement $oServer "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.System']/Model$" $ModelName "MPElement[Name='FTSLIB!Fujitsu.ServerView.System']/Model"
Add-MPElement $oServer "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.System']/SerialNumber$" $SerialNumber "MPElement[Name='FTSLIB!Fujitsu.ServerView.System']/SerialNumber"
Add-MPElement $oServer "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.System']/OperatingSystem$" $OSName "MPElement[Name='FTSLIB!Fujitsu.ServerView.System']/OperatingSystem"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/IPAddress$" $IPAddress "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/IPAddress"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/ChassisModel$" $ChassisModel "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/ChassisModel"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/Cabinets$" $Cabinets "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/Cabinets"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/Manufacturer$" $Manufacturer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/Manufacturer"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/PhysicalMemory$" $totalMemoryUnit "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/PhysicalMemory"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/TotalDisk$ " $TotalLocalDiskUnit "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/TotalDisk"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/BMC$" $BMCIPv4Addr "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/BMC"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/BMC_DNS$" $iRMCDNSName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/BMC_DNS"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/SystemFirmware$" $SystemFirmware "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/SystemFirmware"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/MonitoringAgents$" $MonitoringAgents "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/MonitoringAgents"
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/RaidManager$" $RaidManager "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Server']/RaidManager"
if ($ModelNamePRIMERGYModelGroup -eq "PRIMERGY BX") {
Add-MPElement $oServer "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.BXServer']/MMB$" $MMBIP "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.BXServer']/MMB"
}
$oDiscoveryData.AddInstance($oServer)

#***** Create instance of Health Collections
Debug-Out "Create Health Collections instance: CollectionsHost `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.CollectionsHost']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.CollectionsHost']$")
Add-ObjectData $oInst "Fujitsu.HealthCollections" $PrincipalName
$oDiscoveryData.AddInstance($oInst)

#***** Create instance of Create instance of Software Components
Debug-Out "Create Software Components instance: SoftwareComponents `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SoftwareComponents']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SoftwareComponents']$")
Add-ObjectData $oInst "Software Components" $PrincipalName
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName"
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsSoftware `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsSoftware']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsSoftware']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

#***** Create instance of SCCI (ServerView) component
Debug-Out "Create SCCIManagement instance: SCCIManagement `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SCCIManagement']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SCCIManagement']$")
Add-SoftwareData $oInst $SVAgentName "Service 'SrvCtrl.exe'" $SVAgentVersion $PrincipalName $BMCIPv4Addr $iRMCDNSName
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create $SVAgentVersionString instance: ServerViewAgentsVersion `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewAgentsVersion']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewAgentsVersion']$")
Add-SoftwareVersionData $oInst $SVAgentVersionString $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewAgentsVersion']/Version$" $SVAgentVersion "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewAgentsVersion']/Version"
$oDiscoveryData.AddInstance($oInst)

#***** Create instance of WMI (Windows Management Instrumentation) component
Debug-Out "Create WMIManagement instance: WMIManagement `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.WMIManagement']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.WMIManagement']$")
Add-SoftwareData $oInst "Windows Management Instrumentation" "None" $WMIVersion $PrincipalName $BMCIPv4Addr $iRMCDNSName
$oDiscoveryData.AddInstance($oInst)

#if (($SVRaidVersion -ne "") -and ($SVRaidVersion -gt "3.1.4")) {
if ($SVRaidVersion -ne "") {
Debug-Out "Create RAIDManagement instance: RaidManagement `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidManagement']$" $DBG_SCOM
#***** Create instance of ServerView RAID component
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidManagement']$")
Add-SoftwareData $oInst $SVRaidName "Service 'amService.exe'" $SVRaidVersion $PrincipalName $BMCIPv4Addr $iRMCDNSName
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create $SVRaidVersionString instance: ServerViewRaidVersion `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewRaidVersion']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewRaidVersion']$")
Add-SoftwareVersionData $oInst $SVRaidVersionString $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewRaidVersion']/Version$" $SVRaidVersion "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerViewRaidVersion']/Version"
$oDiscoveryData.AddInstance($oInst)
}
} else {
Debug-Out "script:oDiscoveryEmptyData, Exit" $DBG_INFO
$oDiscoveryEmptyData
exit 1
}
}

# check saved PRIMERGY Server Data
#--------------------------------------------------------------
$SCOMAgentVersion = Get-PYServerData "AgentVersion"
# No SVAgent Version means, all component data have been deleted or this is a new server
if ($SCOMAgentVersion -eq "") {
for ($index = 0; $index -le $OTHER; $index++) {
$script:ComponentsPYServerData[$index] = -1
$script:ComponentsPYServerDataValid[$index] = ""
}
} else {
for ($index = 0; $index -le $OTHER; $index++) {
$script:ComponentsPYServerData[$index] = Get-PYServerData $script:ComponentsStateList[$index]
if ($Null -eq $script:ComponentsPYServerData[$index]) { $script:ComponentsPYServerData[$index] = -1 }
$ComponentsPYServerDataValid[$index] = Get-PYServerData "$($script:ComponentsStateList[$index])Valid"
}
}

# save SVAgent Version if necessary
if (($SCOMAgentVersion -eq "") -or ($SCOMAgentVersion -ne $SVAgentVersion)) {
Save-PYServerData "AgentVersion" $SVAgentVersion
}

# Management Controller
#---------------------------------------------------------------
$componentSubSystemType = $MGMTCTRL
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0

if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYManagementController"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
# Some of our servers do have some sort of BMC, but it is no proper iRMC. Skip these.
if ([string]::IsNullOrEmpty($objItem.ElementName) -and $objItem.HealthState -eq 0) {
Debug-Out "Found some minor BMC which cannot be monitored. Skip." $DBG_INFO
} else {
$script:componentNameArray[$index] = $objItem.ElementName
Debug-Out "$($script:ComponentsList[$componentSubSystemType]): '$($script:componentNameArray[$index])'" $DBG_INFO
$index = 1
}
}
}

# Check BMC FW only if there really is a BMC
if ($index -ne 0) {
$index = 0
$SVAgentClass = "SVS_PGYSoftwareIdentity"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass WHERE ElementName = '$($script:componentNameArray[$index])'" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ("$($objItem.ElementName)".Tolower().Contains("irmc")) {
$iRMCFirmware = "$($objItem.VersionString)"
Debug-Out "Firmware Version: $iRMCFirmware" $DBG_INFO
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.VersionString: $($objItem.VersionString)" $DBG_DESC
$script:componentInfoArray[$index] = "Firmware Version: $iRMCFirmware"
$index = 1
}
}
}
}
} else {
$script:componentNameArray[$index] = Get-ScciData 0xC00 0x508 0 $script:Cabinet
if (-not [string]::IsNullOrEmpty($script:componentNameArray[$index])) {
$iRMCFirmware = Get-ScciData 0xC00 0x506 0 $script:Cabinet
$script:componentInfoArray[$index] = "Firmware Version: $iRMCFirmware"
Debug-Out "$($script:ComponentsList[$componentSubSystemType]): '$($script:componentNameArray[$index])'" $DBG_INFO
Debug-Out "Firmware Version: $iRMCFirmware" $DBG_INFO
$index = 1
} else {
Debug-Out "Found some minor BMC which cannot be monitored. Skip." $DBG_INFO
}
}

$script:componentNames = $script:componentNameArray[0]
$script:componentInfos = $script:componentInfoArray[0]
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: ManagementController `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementController']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementController']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementController']/FirmwareVersion$" $iRMCFirmware "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementController']/FirmwareVersion"
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsManagementController `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsManagementController']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsManagementController']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Processor
#-------------------------------------
$componentSubSystemType = $PROCESSOR
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0

$SCCIIndex = Get-SubsystemData $componentSubSystemType
Debug-Out "Number of Processors: $SCCIIndex" $DBG_INFO

if ($script:CIMProvider -eq $True) {
if ($SCCIIndex -gt 0) {
$SVAgentClass = "SVS_PGYProcessor"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
$index = 0
foreach ($objItem in $CimData) {
$script:componentNameArray[$index] = $objItem.ElementName
$script:componentInfoArray[$index] = $objItem.Name
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.Name: $($objItem.Name)" $DBG_DESC
#Debug-Out "Processor $($index): '$($script:componentNameArray[$index])', Type: '$($script:componentInfoArray[$index])'" $DBG_INFO
$index ++
}
}

$SVAgentClass = "SVS_PGYProcessorCapabilities"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
$i = 0
foreach ($objItem in $CimData) {
Debug-Out "\$($SVNamespace):$SVAgentClass.NumberOfProcessorEnabledCores: $($objItem.NumberOfProcessorEnabledCores)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.NumberOfHardwareEnabledThreads: $($objItem.NumberOfHardwareEnabledThreads)" $DBG_DESC
$script:componentInfoArray[$i] = "$($script:componentInfoArray[$i]) / Enabled Cores: $($objItem.NumberOfProcessorEnabledCores), Enabled Threads: $($objItem.NumberOfHardwareEnabledThreads)"
Debug-Out "Processor $($i): '$($script:componentNameArray[$i])', Type: '$($script:componentInfoArray[$i])'" $DBG_INFO
$i ++
}
}
}
$index = $SCCIIndex
} else {
if ($script:SVAgentRunning -eq $True) {
$index = $SCCIIndex
if ($SCCIIndex -gt 0) {
for ($i = 0; $i -lt $SCCIIndex; $i++) {
$strComponentValue = Get-ScciData 0x605 0 $i $script:Cabinet # CPU Model Name
if ($strComponentValue -ne "") {
$intComponentValue = Get-ScciData 0x606 0 $i $script:Cabinet # No. of logical CPUs (Cores)
$script:componentInfoArray[$i] = "$strComponentValue / Logical Cores: $intComponentValue"
}

if ($script:componentInfoArray[$i] -ne "") {
Debug-Out "Processor $($i): '$($script:componentNameArray[$i])', Type: '$($script:componentInfoArray[$i])'" $DBG_INFO
}
}
}
}
}

$script:componentNames = "Processors: $index"
$script:componentInfos = ""
if ($script:componentCountEmpty -gt 0) { $script:componentInfos = "Not populated Processors: $script:componentCountEmpty" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: Processors `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Processors']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Processors']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsProcessors `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsProcessors']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsProcessors']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: Processor `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Processor']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Processor']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Processor']/ProcInfo$" $script:componentInfoArray[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Processor']/ProcInfo"
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Memory
#-------------------------------------------
$componentSubSystemType = $MEMORY
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0
$totalMemory = 0
$devType = @("") * 50
$devNo = @(0) * 50
$devProperty1 = @("") * $cMAXINDEX
$devProperty2 = @("") * $cMAXINDEX
$devProperty3 = @("") * $cMAXINDEX
$devProperty4 = @("") * $cMAXINDEX

$SCCIIndex = Get-SubsystemData $componentSubSystemType
Debug-Out "Number of Memory Modules: $SCCIIndex" $DBG_INFO

if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYPhysicalMemory"
if ($SCCIIndex -gt 0) {
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

$index = 0
$j = 0
for ($i = 0; $i -lt $SCCIIndex; $i++) {
if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ($script:componentNameArray[$j] -eq $objItem.Caption) {
Debug-Out "\$($SVNamespace):$SVAgentClass.Caption: $($objItem.Caption)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.Capacity: $($objItem.Capacity)" $DBG_DESC
$script:componentNameArray[$index] = $objItem.Caption
$totalMemory = $totalMemory + $objItem.Capacity
$script:componentInfoArray[$index] = ConvertTo-MatchingUnit $objItem.Capacity
$devProperty1[$index] = $script:componentInfoArray[$index]
$devProperty2[$index] = $objItem.Manufacturer
$devProperty3[$index] = $objItem.PartNumber
$devProperty4[$index] = $objItem.SerialNumber
Debug-Out "Memory $($index): '$($script:componentNameArray[$index])', size: $($objItem.Capacity) ($($script:componentInfoArray[$index]))" $DBG_INFO
$index ++
$j ++
}
}
}
}
}
$SCCIIndex = $index
} else {
if ($script:SVAgentRunning -eq $True) {
if ($SCCIIndex -gt 0) {
$SCCIIndex = Get-ScciData 0x700 0 0 $script:Cabinet
$index = 0

for ($i = 0; $i -lt $SCCIIndex; $i++) {
$strComponentValue = Get-ScciData 0x702 0 $i $script:Cabinet # Number of memory slots
$intComponentValue = Get-ScciData 0x701 0 $i $script:Cabinet # memory slot state: 0 = empty
if ($intComponentValue -ne 0) {
$intComponentValue = Get-ScciData 0x70A 0 $i $script:Cabinet # memory size
$intComponentValue = $intComponentValue * 1024 * 1024 #*** Size in GB
$script:componentNameArray[$index] = $strComponentValue # make sure we get the correct memory name here
$script:componentInfoArray[$index] = ConvertTo-MatchingUnit $intComponentValue
$devProperty1[$index] = $script:componentInfoArray[$index]
$devProperty2[$index] = Get-ScciData 0xC00 0x030A $i $script:Cabinet # Manufacturer
$devProperty3[$index] = Get-ScciData 0xC00 0x0301 $i $script:Cabinet # PartNumber
$devProperty4[$index] = Get-ScciData 0xC00 0x0300 $i $script:Cabinet # SerialNumber
$totalMemory = $totalMemory + $intComponentValue
Debug-Out "Memory $($index): '$($script:componentNameArray[$index])', size: $intComponentValue ($($script:componentInfoArray[$index]))" $DBG_INFO
$index ++
}
}
}
}
$SCCIIndex = $index
}

$totalMemory = ConvertTo-MatchingUnit $totalMemory
Debug-Out "Physical Memory: $totalMemory" $DBG_INFO

$script:componentNames = "Memory Modules: $index"
$script:componentInfos = "Overall Memory: $totalMemory"

for ($index = 0; $index -lt $SCCIIndex; $index++) {
for ($i = 0; $i -lt 50; $i++) {
if ($devType[$i] -eq "") {
$devType[$i] = $script:componentInfoArray[$index]
$devNo[$i] = 1
break
} elseif ($script:componentInfoArray[$index] -eq $devType[$i]) {
$devNo[$i] = $devNo[$i] + 1
break
}
}
}

$script:componentInfos = "$($script:componentInfos); "
for ($i = 0; $i -lt 50; $i++) {
if ($devType[$i] -ne "") {
$script:componentInfos = "$($script:componentInfos)'$($devType[$i])': $($devNo[$i]), "
}
}
$script:componentInfos = $script:componentInfos.Substring(0, $script:componentInfos.Length - 2)

if ($script:componentCountEmpty -gt 0) { $script:componentInfos = "$($script:componentInfos); Not populated Memory Modules: $script:componentCountEmpty" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: Memory `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Memory']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Memory']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsMemory `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsMemory']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsMemory']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: MemoryModule `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/Capacity$" $script:componentInfoArray[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/Capacity"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/Manufacturer$" $devProperty2[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/Manufacturer"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/PartNumber$" $devProperty3[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/PartNumber"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/SerialNumber$" $devProperty4[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.MemoryModule']/SerialNumber"
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Storage
#-----------------------------
$componentSubSystemType = $STORAGE
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$totalDiskSpace = 0
$index = 0
$devType = @("") * 50
$devNo = @(0) * 50
$devProperty1 = @("") * $cMAXINDEX
$devProperty2 = @("") * $cMAXINDEX
$devProperty3 = @("") * $cMAXINDEX
$devProperty4 = @("") * $cMAXINDEX
$devProperty5 = @("") * $cMAXINDEX

$SVAgentClass = "Win32_DiskDrive"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
Debug-Out "\$($cimv2NS):$SVAgentClass.Model: $($objItem.Model)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.MediaType: $($objItem.MediaType)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.Caption: $($objItem.Caption)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.Size: $($objItem.Size)" $DBG_DESC
if ("$($objItem.MediaType)".Contains("Removable")) {
Debug-Out "Skipping removable media '$($objItem.Caption)'." $DBG_INFO
} elseif ("$($objItem.MediaType)".Contains("External")) {
Debug-Out "Skipping external media '$($objItem.Caption)'." $DBG_INFO
} elseif ("$($objItem.Model)".Contains("Virtual")) {
Debug-Out "Skipping virtual disk '$($objItem.Caption)'." $DBG_INFO
} else {
$script:componentNameArray[$index] = $objItem.Caption
if ($objItem.Size -gt 0) {
$totalDiskSpace = $totalDiskSpace + $objItem.Size
$script:componentInfoArray[$index] = ConvertTo-MatchingUnit $objItem.Size
$devProperty1[$index] = $script:componentInfoArray[$index]
$devProperty3[$index] = $objItem.Model
$devProperty5[$index] = $objItem.InterfaceType
# these two are only available for OS &gt; W2K3
if ([convert]::ToInt32("$OSVersion".Substring(0, 1), 10) -gt 5) {
$devProperty2[$index] = $objItem.FirmwareRevision
$devProperty4[$index] = $objItem.SerialNumber
}
}
Debug-Out "Storage $($index): '$($script:componentNameArray[$index])', size: $($objItem.Size) ($($script:componentInfoArray[$index]))" $DBG_INFO

if ($index -ge $cMAXINDEX) {
Debug-Out "Max. no. of storage instances reached/exceeded" $DBG_INFO
break
}
$index ++
}
}
}
Debug-Out "Number of Storage Devices: $index" $DBG_INFO

$totalDiskSpace = ConvertTo-MatchingUnit $totalDiskSpace
Debug-Out "Disk Space: $totalDiskSpace" $DBG_INFO

$script:componentNames = "Storage Disks: $index"
$script:componentInfos = "Overall Disk Space: $totalDiskSpace"

for ($j = 0; $j -lt $index; $j++) {
for ($i = 0; $i -lt 50; $i++) {
if ($devType[$i] -eq "") {
$devType[$i] = $script:componentInfoArray[$j]
$devNo[$i] = 1
break
} elseif ($script:componentInfoArray[$j] -eq $devType[$i]) {
$devNo[$i] = $devNo[$i] + 1
break
}
}
}

$script:componentInfos = "$($script:componentInfos); "
for ($i = 0; $i -lt 50; $i++) {
if ($devType[$i] -ne "") {
$script:componentInfos = "$($script:componentInfos)'$($devType[$i])': $($devNo[$i]), "
}
}
$script:componentInfos = $script:componentInfos.Substring(0, $script:componentInfos.Length - 2)

Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: ServerStorage `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerStorage']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerStorage']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsServerStorage `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsServerStorage']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsServerStorage']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: StorageDisk `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/Size$" $script:componentInfoArray[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/Size"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/FirmwareRevision$" $devProperty2[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/FirmwareRevision"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/ModelName$" $devProperty3[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/ModelName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/SerialNumber$" $devProperty4[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/SerialNumber"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/InterfaceType$" $devProperty5[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.StorageDisk']/InterfaceType"
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Network Adapter (Ethernet)
#-------------------------------------------
$componentSubSystemType = $NETWORK
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0
$devProperty1 = @("") * $cMAXINDEX
$devProperty2 = @("") * $cMAXINDEX

$SVAgentClass = "Win32_NetworkAdapter"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $cimv2NS

if ($script:WMIInstanceValid -eq $True) {
$i = 0
foreach ($objItem in $CimData) {
Debug-Out "\$($cimv2NS):$SVAgentClass.ProductName: $($objItem.ProductName)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.AdapterType: $($objItem.AdapterType)" $DBG_DESC

try {
if (! "$($objItem.ProductName)".Contains("Microsoft") -and "$($objItem.AdapterType)".Contains(" 802.3")) {
Debug-Out "\$($cimv2NS):$SVAgentClass.Name: $($objItem.Name)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.NetConnectionStatus: $($objItem.NetConnectionStatus)" $DBG_DESC
Debug-Out "\$($cimv2NS):$SVAgentClass.MACAddress: $($objItem.MACAddress)" $DBG_DESC

$script:componentNameArray[$index] = "$($objItem.Name) ($index)"
$devProperty1[$index] = $objItem.NetConnectionID
$devProperty2[$index] = $objItem.ServiceName

$script:componentInfoArray[$index] = ""
if ($objItem.MACAddress.Length -ne 0) {
$script:componentInfoArray[$index] = $objItem.MACAddress
}
Debug-Out "Network $($index): '$($script:componentNameArray[$index])' ($($objItem.ServiceName)), $($script:componentInfoArray[$index])" $DBG_DATA

if ($index -ge $cMAXINDEX) {
Debug-Out "Max. no. of Network Adapter/Port instances reached/exceeded" $DBG_INFO
break
}
$index ++
}
} catch {
Debug-Out "Skipping Network Adapter: '$($objItem.ProductName)' ($($objItem.AdapterType))" $DBG_DATA
}
}
}
Debug-Out "Number of Network Devices: $index" $DBG_INFO
Debug-Out "Number of Disabled Network Devices: $i" $DBG_INFO

$script:componentNames = "Network Devices: $index"
$script:componentInfos = ""
if ($i -gt 0) { $script:componentInfos = "Disabled Network Devices: $i" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: ServerNetworks `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerNetworks']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerNetworks']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsServerNetworks `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsServerNetworks']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsServerNetworks']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: NetworkDevice `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']/MacAddress$" $script:componentInfoArray[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']/MacAddress"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']/NetConnectionID$" $devProperty1[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']/NetConnectionID"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']/ServiceName$" $devProperty2[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.NetworkDevice']/ServiceName"
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Fans
#---------------------------------------------
$componentSubSystemType = $FANS
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status

$index = Get-SubsystemData $componentSubSystemType
Debug-Out "Number of Fans: $index" $DBG_INFO

$script:componentNames = "Fan Devices: $index"
$script:componentInfos = ""
if ($script:componentCountEmpty -gt 0) { $script:componentInfos = "Not populated Fans: $($script:componentCountEmpty)" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: Fans `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Fans']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Fans']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsFans `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsFans']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsFans']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: Fan `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Fan']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Fan']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Temperatures
#---------------------------
$componentSubSystemType = $TEMPERATURE
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0

$index = Get-SubsystemData $componentSubSystemType
Debug-Out "Number of Temperature Sensors: $index" $DBG_INFO

$script:componentNames = "Temperature Sensors: $index"
$script:componentInfos = ""
if ($script:componentCountEmpty -gt 0) { $script:componentInfos = "Not populated Temperature Sensors: $($script:componentCountEmpty)" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: TemperatureSensors `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.TemperatureSensors']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.TemperatureSensors']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsTemperatureSensors `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsTemperatureSensors']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsTemperatureSensors']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: TemperatureSensor `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.TemperatureSensor']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.TemperatureSensor']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Voltages
#---------------------------
$componentSubSystemType = $VOLTAGES
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0

$index = Get-SubsystemData $componentSubSystemType
Debug-Out "Number of Voltage Sensors: $index" $DBG_INFO

$script:componentNames = "Voltage Sensors: $index"
$script:componentInfos = ""
if ($script:componentCountEmpty -gt 0) { $script:componentInfos = "Not populated Voltage Sensors: $($script:componentCountEmpty)" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: VoltageSensors `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.VoltageSensors']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.VoltageSensors']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsVoltageSensors `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsVoltageSensors']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsVoltageSensors']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: VoltageSensor `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.VoltageSensor']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.VoltageSensor']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Power Supplies
#-----------------------------
$componentSubSystemType = $POWERSUPPLY
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0
$SCCIIndex = 0
$devProperty1 = @("") * $cMAXINDEX
$devProperty2 = @("") * $cMAXINDEX

$index = Get-SubsystemData $componentSubSystemType
Debug-Out "Number of Power Supplies: $index" $DBG_INFO

if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYPowerProductionSensor"
if ($index -gt 0) {
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

$j = 0
for ($i = 0; $i -lt $index; $i++) {
if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
if ($script:componentNameArray[$j] -eq "$($objItem.DeviceID) $($objItem.ElementName)".Replace("-", "/")) {
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.DeviceID: $($objItem.DeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.NominalReading: $($objItem.NominalReading)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.CurrentReading: $($objItem.CurrentReading)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.UnitModifier: $($objItem.UnitModifier)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.DeviceID: $($objItem.DeviceID)" $DBG_DESC
$DevID = $objItem.DeviceID -Split "-"
$DevCabinet = [convert]::ToInt32($DevID[0], 16)
$DevIndex = [convert]::ToInt32($DevID[1], 16)
$script:componentNameArray[$j] = "$DevCabinet/$DevIndex $($objItem.ElementName)"
if ($objItem.NominalReading -gt 0) {
$devProperty1[$j] = "$($objItem.NominalReading * [math]::pow(10, $objItem.UnitModifier))W" # Nominal Reading
$devProperty2[$j] = "$($objItem.CurrentReading * [math]::pow(10, $objItem.UnitModifier))W" # Current Reading
} else {
$devProperty1[$j] = "N/A"
$devProperty2[$j] = ""
}
Debug-Out "PSU $($j): '$($script:componentNameArray[$j])', Nominal Power: $($devProperty1[$j]), Current Power: $($devProperty2[$j])" $DBG_INFO
$j ++
}
}
}
}
}
} else {
if ($script:SVAgentRunning -eq $True) {
if ($index -gt 0) {
$SCCIIndex = Get-ScciData 0x500 0 0 $script:Cabinet
$j = 0
$cab = 0
$l = 0
for ($i = 0; $i -lt $SCCIIndex; $i++) {
$Status = $script:oSwitch.ScciQuery(0x504, 0, $l, $script:CabinetArray[$cab], 0, [REF]$strComponentValue, 0)
if ($Status -ne 0) {
Debug-Out "oSwitch: No Data for opCode=0x504 opCodeExt=0x0 objIndex=$l cabID=$($script:CabinetArray[$cab])" $DBG_DESC
$cab = $cab + 1
$l = 0
} else {
Debug-Out "oSwitch: opCode=0x504 opCodeExt=0x0 objIndex=$l cabID=$($script:CabinetArray[$cab]) -&gt; scciValue = '$strComponentValue'" $DBG_DESC
}

if ($script:componentNameArray[$j] -eq "$($script:CabinetArray[$cab])/$l $strComponentValue") {
$devProperty1[$j] = Get-ScciData 0x507 0 $l $script:CabinetArray[$cab]
if ($devProperty1[$j] -gt 0) {
$devProperty1[$j] = "$($devProperty1[$j])W"
$devProperty2[$j] = "$(Get-ScciData 0x506 0 $l $script:CabinetArray[$cab])W"
} else {
$devProperty1[$j] = "N/A"
}
Debug-Out "PSU $($j): '$($script:componentNameArray[$j])', Nominal Power: $($devProperty1[$j]), Current Power: $($devProperty2[$j])" $DBG_INFO
$j ++
}
$l ++
}
}
}
}

$script:componentNames = "Power Supplies: $index"
$script:componentInfos = ""
if ($script:componentCountEmpty -gt 0) { $script:componentInfos = "Not populated Power Supplies: $($script:componentCountEmpty)" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: PowerSupplies `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerSupplies']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerSupplies']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsPowerSupplies `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsPowerSupplies']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsPowerSupplies']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

for ($i = 0; $i -lt $index; $i++) {
Debug-Out "Create $($script:componentNameArray[$i]) instance: PowerSupply `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerSupply']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerSupply']$")
Add-SimpleDeviceData $oInst $script:componentNameArray[$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerSupply']/Nominal$" $devProperty1[$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerSupply']/Nominal"
$oDiscoveryData.AddInstance($oInst)
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** Power Consumption
#-----------------------------
$componentSubSystemType = $POWERCONSUMP
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status
$index = 0

if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYPowerConsumptionSensor"
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
# Info: SV Agents SCCI only supply the 'Total Power' sensor (#E0) with sensible values.
# Ignore all others here
Debug-Out "\$($SVNamespace):$SVAgentClass.DeviceID: $($objItem.DeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC

if ("$($objItem.DeviceID)".Tolower().Contains("e0")) {
if ("$($objItem.ElementName)".Contains("Total Power")) {
if ("$($objItem.ElementName)".Contains("Out")) {
Debug-Out "Do not use OutPut PowerConsumption Sensor $($objItem.ElementName)" $DBG_INFO
} else {
Debug-Out "PowerConsumption Sensor $($objItem.ElementName)" $DBG_INFO
$script:componentNameArray[$index] = "Power Level"
$script:componentInfoArray[$index] = "Sensor: $($objItem.ElementName)"
$index ++
}
} else {
Debug-Out "Skip PowerConsumption Sensor $($objItem.ElementName)" $DBG_DATA
}
} else {
Debug-Out "Ignore PowerConsumption Sensor $($objItem.ElementName)" $DBG_DATA
}
}
}
} else {
if ($script:SVAgentRunning -eq $True) {
$PCComponentClass = @(0x00, 0x1D, 0x20, 0x03, 0x0A, 0xE0)
$PCComponentArray = @("All", "Fan", "Memory", "CPU", "Power Supply", "Total")

# Info: ServerView Agents SCCI only supply the 'Total Power' sensor with sensible values.
# Ignore all others here for now and only request Total Power
$PCIndex = 5
#for ($PCIndex = 1; $PCIndex -lt $PCComponentClass.Length; $PCIndex ++) {
$SCCIIndex = Get-ScciData 0x0531 $PCComponentClass[$PCIndex] 0 $script:Cabinet
if ($Null -eq $SCCIIndex) { $SCCIIndex = 0 }
Debug-Out "PowerConsumptionClassComponents '$($PCComponentArray[$PCIndex])' Number: $SCCIIndex" $DBG_DESC
for ($i=0; $i -lt $SCCIIndex; $i++) {
$PCDesignation = Get-ScciData 0x0532 $PCComponentClass[$PCIndex] $i $script:Cabinet
if ("$PCDesignation".Contains("Total Power")) {
if ("$PCDesignation".Contains("Out")) {
Debug-Out "Do not use OutPut PowerConsumption Sensor $PCDesignation" $DBG_INFO
} else {
Debug-Out "PowerConsumption Sensor '$PCIndex/$i' (0x$('{0:X}' -f $PCComponentClass[$PCIndex])) '$PCDesignation'" $DBG_INFO
$script:componentNameArray[$index] = "Power Level"
$script:componentInfoArray[$index] = "Sensor: $PCDesignation"
$index ++
}
} else {
Debug-Out "Ignore PowerConsumption Sensor $PCDesignation" $DBG_INFO
}
}
#}
}
}
Debug-Out "Number of Power Consumption Sensors: $index" $DBG_INFO

$script:componentNames = $script:componentNameArray[0]
$script:componentInfos = $script:componentInfoArray[0]
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($index -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: PowerConsumption `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerConsumption']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.PowerConsumption']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsPowerConsumption `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsPowerConsumption']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsPowerConsumption']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$componentSubSystemType])'" $DBG_INFO
}


#*** RAID Subsystem
#-----------------------------
$componentSubSystemType = $RAIDSUBSYSTEM
Debug-Out "***** $($script:ComponentsList[$RAIDSUBSYSTEM]) *****" $DBG_INFO
Debug-Out "***** $($script:ComponentsList[$PHYSICALDISK]) *****" $DBG_INFO
Debug-Out "***** $($script:ComponentsList[$LOGICALDRIVE]) *****" $DBG_INFO

$CIM_RAIDLevel = @("") * 25
$CIM_RAIDLevel[1] = "Unknown"
$CIM_RAIDLevel[2] = "RAID-0"
$CIM_RAIDLevel[3] = "RAID-01"
$CIM_RAIDLevel[4] = "RAID-1"
$CIM_RAIDLevel[5] = "RAID-1E"
$CIM_RAIDLevel[6] = "RAID-10"
$CIM_RAIDLevel[7] = "RAID-3"
$CIM_RAIDLevel[8] = "RAID-4"
$CIM_RAIDLevel[9] = "RAID-5"
$CIM_RAIDLevel[10] = "RAID-50"
$CIM_RAIDLevel[11] = "RAID-5E"
$CIM_RAIDLevel[12] = "RAID-5EE"
$CIM_RAIDLevel[13] = "RAID-6"
$CIM_RAIDLevel[14] = "ConCat"
$CIM_RAIDLevel[15] = "Single"
$CIM_RAIDLevel[16] = "RAID-60"
$CIM_RAIDLevel[17] = "RAID-1E0"
$CIM_RAIDLevel[18] = "RAID-0CC"
$CIM_RAIDLevel[19] = "RAID-1CC"
$CIM_RAIDLevel[20] = "RAID-1ECC"
$CIM_RAIDLevel[21] = "RAID-5CC"
$CIM_RAIDLevel[22] = "RAID-00"

Clear-Status
$index = 0
$devProperty1 = @("") * $cMAXINDEX
$devProperty2 = @("") * $cMAXINDEX
$devProperty3 = @("") * $cMAXINDEX
$devProperty4 = @("") * $cMAXINDEX
$devProperty5 = @("") * $cMAXINDEX

$MaxAdapter = 10
$MaxLD = 100
$MaxPD = 256

$ctrlIndex = 0
$ldIndex = @(0) * $MaxAdapter
$pdIndex = @(0) * $MaxAdapter
$adapterNameArray = @("") * $MaxAdapter
$adapterInfoArray = @("") * $MaxAdapter

$LDperCtrlNameArray = New-Object 'object[,]' $MaxAdapter, $MaxLD
$LDperCtrlInfoArray = New-Object 'object[,]' $MaxAdapter, $MaxLD
$PDperCtrlNameArray = New-Object 'object[,]' $MaxAdapter, $MaxPD
$PDperCtrlInfoArray = New-Object 'object[,]' $MaxAdapter, $MaxPD

$LDperCtrlPDArray = @{}

$LDProperty1 = New-Object 'object[,]' $MaxAdapter, $MaxLD
$LDProperty2 = New-Object 'object[,]' $MaxAdapter, $MaxLD

$PDProperty1 = New-Object 'object[,]' $MaxAdapter, $MaxPD
$PDProperty2 = New-Object 'object[,]' $MaxAdapter, $MaxPD
$PDProperty3 = New-Object 'object[,]' $MaxAdapter, $MaxPD
$PDProperty4 = New-Object 'object[,]' $MaxAdapter, $MaxPD

$ldIndexAll = 0
$pdIndexAll = 0
$ldInfos = ""
$pdInfos = ""
$pos = 0

if (($script:CIMProvider -eq $True -and $PSVersion.Major -ge 4) -and ($script:CIMRaidProvider -eq $True)) {
$SVAgentClass = "SVS_PGYHostRaidController"
$CimData = @(Get-CimQuery -Query "SELECT * FROM $SVAgentClass" -Namespace $SVNamespace)

if ($script:WMIInstanceValid -eq $True) {
Debug-Out "Number of RAID controllers: $($CimData.Count)" $DBG_INFO

foreach ($objItem in $CimData) {
Debug-Out "\$($SVNamespace):$SVAgentClass.Name: $($objItem.Name)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVAgentClass.Vendor: $($objItem.Vendor)" $DBG_DESC
$adapterNameArray[$pos] = "$($objItem.ElementName)"
$devProperty1[$pos] = $objItem.Vendor
Debug-Out "devProperty1($pos): '$($devProperty1[$pos])'" $DBG_DATA

$DevData = @(Get-CimAssociatedInstance -InputObject $objItem)
if (-not ([string]::IsNullOrEmpty($DevData))) {
Debug-Out "Found $($DevData.Count) Associated Instances for 'SVS_PGYHostRaidController ($($objItem.ElementName))'" $DBG_DATA
foreach ($devItem in $DevData) {
Debug-Out "$($devItem.CreationClassName) / $($devItem.ElementName) / $($devItem.Caption)" $DBG_DATA
}

$pd = 0
foreach ($devItem in $DevData) {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).CreationClassName: $($devItem.CreationClassName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).ElementName: $($devItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Name: $($devItem.Name)" $DBG_DESC

switch ("$($devItem.CreationClassName)") {
"SVS_PGYHostRaidController" {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Vendor: $($devItem.Vendor)" $DBG_DESC
$devProperty1[$pos] = $devItem.Vendor
Debug-Out "devProperty1($pos): '$($devProperty1[$pos])'" $DBG_DATA
}
"SVS_PGYPortController" {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).ProtocolDescription: $($devItem.ProtocolDescription)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).NumberLogicalDevices: $($devItem.NumberLogicalDevices)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).NumberPhysDisks: $($devItem.NumberPhysDisks)" $DBG_DESC

$adapterNameArray[$pos] = "$($devItem.ElementName)"
$adapterInfoArray[$pos] = "$($devItem.ProtocolDescription)"
if ($adapterInfoArray[$pos] -eq "") { $adapterInfoArray[$pos] = "Unknown" }
Debug-Out "RAID Controller $pos, Name $($adapterNameArray[$pos]), $($adapterInfoArray[$pos])" $DBG_INFO

Debug-Out "Number of Phys. Disks on RAID Adapter $($adapterNameArray[$pos]): $($devItem.NumberPhysDisks)" $DBG_INFO
Debug-Out "Number of Log. Drives on RAID Adapter $($adapterNameArray[$pos]): $($devItem.NumberLogicalDevices)" $DBG_INFO

if ("$($devItem.PCIDeviceID)" -ne "") {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCIBusNumber: $($devItem.PCIBusNumber) 0x$('{0:X4}' -f $devItem.PCIBusNumber)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCIDeviceID: $($devItem.PCIDeviceID) 0x$('{0:X4}' -f $devItem.PCIDeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCIDeviceNumber: $($devItem.PCIDeviceNumber) 0x$('{0:X4}' -f $devItem.PCIDeviceNumber)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCIFunctionNumber: $($devItem.PCIFunctionNumber) 0x$('{0:X4}' -f $devItem.PCIFunctionNumber)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCISubDeviceID: $($devItem.PCISubDeviceID) 0x$('{0:X4}' -f $devItem.PCISubDeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCISubVendorID: $($devItem.PCISubVendorID) 0x$('{0:X4}' -f $devItem.PCISubVendorID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).PCIVendorID: $($devItem.PCIVendorID) 0x$('{0:X4}' -f $devItem.PCIVendorID)" $DBG_DESC

$PNPDeviceID = "VEN_$('{0:X4}' -f $devItem.PCIVendorID)&amp;DEV_$('{0:X4}' -f $devItem.PCIDeviceID)&amp;SUBSYS_$('{0:X4}' -f $devItem.PCISubDeviceID)$('{0:X4}' -f $devItem.PCISubVendorID)"
Debug-Out "PNPDeviceID : $PNPDeviceID" $DBG_DESC
$PciData = Get-CimQuery -Query "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID Like '%$PNPDeviceID%'" -Namespace $cimv2NS
Debug-Out "\$($cimv2NS):Win32_PnPEntity.Service: $($PciData.Service)" $DBG_DESC

$SwData = Get-CimQuery -Query "SELECT * FROM SVS_PGYSoftwareIdentity WHERE Name Like '%$($PciData.Service)%'" -Namespace $SVNamespace
Debug-Out "\$($SVNamespace):SVS_PGYSoftwareIdentity.VersionString: $($SwData.VersionString)" $DBG_DESC
$devProperty3[$pos] = "$($SwData.VersionString)" # Driver
}

$CtrlData = @(Get-CimAssociatedInstance -InputObject $devItem)
if (-not ([string]::IsNullOrEmpty($CtrlData))) {
Debug-Out "Found $($CtrlData.Count) Associated Instances for 'SVS_PGYPortController ($($devItem.ElementName))'" $DBG_DATA
foreach ($ctrlItem in $CtrlData) {
Debug-Out "$($ctrlItem.CreationClassName) / $($ctrlItem.ElementName) / $($ctrlItem.Caption)" $DBG_DATA
}

foreach ($ctrlItem in $CtrlData) {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).CreationClassName: $($ctrlItem.CreationClassName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).ElementName: $($ctrlItem.ElementName)" $DBG_DESC

switch ("$($devItem.CreationClassName)") {
default {
Debug-Out "default '$($ctrlItem.CreationClassName)' / '$($ctrlItem.Caption)'" $DBG_DATA
switch ("$($ctrlItem.Caption)") {
"Firmware Version" {
Debug-Out "\$($SVNamespace):$($ctrlItem.CreationClassName).Caption: $($ctrlItem.Caption)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($ctrlItem.CreationClassName).Manufacturer: $($ctrlItem.Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($ctrlItem.CreationClassName).VersionString: $($ctrlItem.VersionString)" $DBG_DESC
$devProperty3[$pos] = $ctrlItem.VersionString # FirmwareVersion
}
}
}
}
}
}

$devProperty2[$pos] = "N/A" # SerialNumber
Debug-Out "devProperty2($pos): '$($devProperty2[$pos])'" $DBG_DATA
Debug-Out "devProperty3($pos): '$($devProperty3[$pos])'" $DBG_DATA
}
"SVS_PGYDiskDrive" {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).DeviceID: $($devItem.DeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).StatusDescriptions: $($devItem.StatusDescriptions)" $DBG_DESC

$SVDiskClass = "SVS_PGYDiskExtent"
$DiskData = @(Get-CimQuery -Query "SELECT * FROM $SVDiskClass WHERE ElementName='$($devItem.ElementName)'" -Namespace $SVNamespace)
if (-not ([string]::IsNullOrEmpty($DiskData))) {
Debug-Out "\$($SVNamespace):$SVDiskClass.ElementName: $($DiskData[0].ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDiskClass.ConsumableBlocks: $($DiskData[0].ConsumableBlocks)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDiskClass.BlockSize: $($DiskData[0].BlockSize)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDiskClass.NumberOfBlocks: $($DiskData[0].NumberOfBlocks)" $DBG_DESC

if ($DiskData[0].ElementName -ne "") {
$PDperCtrlNameArray[$pos,$pd] = "$($DiskData[0].ElementName) ($pos/$pd)"
} else {
$PDperCtrlNameArray[$pos,$pd] = "Physical Disk ($pos/$pd)"
}
$PDperCtrlInfoArray[$pos,$pd] = ConvertTo-MatchingUnit "$($DiskData[0].NumberOfBlocks * $DiskData[0].BlockSize)"
if ("$($DiskData[0].StatusDescriptions)" -ne "") {
$PDInfo = ""
foreach ($ost in $DiskData[0].StatusDescriptions) {
if ("$PDInfo" -ne "") { $PDInfo = "$PDInfo, "}
$PDInfo = "$PDInfo$ost"
}
}
#$PDperCtrlInfoArray[$pos,$pd] = "$($PDperCtrlInfoArray[$pos,$pd]), $PDInfo"
}

$SVDiskClass = "SVS_PGYPhysicalDiskPackage"
$DiskData = @(Get-CimQuery -Query "SELECT * FROM $SVDiskClass WHERE ElementName='$($devItem.ElementName)'" -Namespace $SVNamespace)
if (-not ([string]::IsNullOrEmpty($DiskData))) {
Debug-Out "\$($SVNamespace):$SVDiskClass.SerialNumber: $($DiskData[0].SerialNumber)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDiskClass.Manufacturer: $($DiskData[0].Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDiskClass.Model: $($DiskData[0].Model)" $DBG_DESC
$PDProperty2[$pos,$pd] = $DiskData[0].Model # Product
$PDProperty3[$pos,$pd] = $DiskData[0].SerialNumber # SerialNumber
$PDProperty4[$pos,$pd] = $DiskData[0].Manufacturer # Vendor"
}

$DiskData = @(Get-CimAssociatedInstance -InputObject $devItem)
if (-not ([string]::IsNullOrEmpty($DiskData))) {
Debug-Out "Found $($DiskData.Count) Associated Instances for 'SVS_PGYDiskDrive ($($devItem.ElementName))'" $DBG_DATA
foreach ($diskItem in $DiskData) {
Debug-Out "$($diskItem.CreationClassName) / $($diskItem.ElementName) / $($diskItem.Caption)" $DBG_DATA
}

foreach ($diskItem in $DiskData) {
Debug-Out "$($diskItem.CreationClassName) / $($diskItem.ElementName) / $($diskItem.Caption)" $DBG_DATA
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).CreationClassName: $($diskItem.CreationClassName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).ElementName: $($diskItem.ElementName)" $DBG_DESC

switch ("$($devItem.CreationClassName)") {
default {
Debug-Out "default '$($diskItem.CreationClassName)' / '$($diskItem.Caption)'" $DBG_DATA
switch ("$($diskItem.Caption)") {
"Firmware Version" {
Debug-Out "\$($SVNamespace):$($diskItem.CreationClassName).Caption: $($diskItem.Caption)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($diskItem.CreationClassName).Manufacturer: $($diskItem.Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($diskItem.CreationClassName).VersionString: $($diskItem.VersionString)" $DBG_DESC
$PDProperty1[$pos,$pd] = $diskItem.VersionString # FirmwareVersion
}
}
}
}
}
}
Debug-Out "PDProperty1($pos,$pd): '$($PDProperty1[$pos,$pd])'" $DBG_DATA
Debug-Out "PDProperty2($pos,$pd): '$($PDProperty2[$pos,$pd])'" $DBG_DATA
Debug-Out "PDProperty3($pos,$pd): '$($PDProperty3[$pos,$pd])'" $DBG_DATA
Debug-Out "PDProperty4($pos,$pd): '$($PDProperty4[$pos,$pd])'" $DBG_DATA

if ("$($script:componentNameArray[$index])" -Like "*SSD*") {
Debug-Out "SSD $pos/$($pd): $($PDperCtrlNameArray[$pos,$pd]) $($PDperCtrlInfoArray[$pos,$pd])" $DBG_INFO
} else {
Debug-Out "Phys. Disk $pos/$($pd): $($PDperCtrlNameArray[$pos,$pd]) $($PDperCtrlInfoArray[$pos,$pd])" $DBG_INFO
}
$pdIndex[$pos]++
$pdIndexAll++
$pd++
}
default {
Debug-Out "default '$($devItem.CreationClassName)' / '$($devItem.Caption)'" $DBG_DATA
switch ("$($devItem.Caption)") {
"Firmware Version" {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Caption: $($devItem.Caption)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Manufacturer: $($devItem.Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).VersionString: $($devItem.VersionString)" $DBG_DESC
$devProperty4[$pos] = "$($devItem.VersionString)"
Debug-Out "devProperty4($pos): '$($devProperty4[$pos])'" $DBG_DATA
}
"BIOS Version" {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Caption: $($devItem.Caption)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Manufacturer: $($devItem.Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).VersionString: $($devItem.VersionString)" $DBG_DESC
$devProperty5[$pos] = "$($devItem.VersionString)"
Debug-Out "devProperty5($pos): '$($devProperty5[$pos])'" $DBG_DATA
}
default {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Caption: $($devItem.Caption)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).Manufacturer: $($devItem.Manufacturer)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).VersionString: $($devItem.VersionString)" $DBG_DESC
if ("$($devProperty3[$pos])" -eq "") {
$devProperty3[$pos] = "$($devItem.VersionString)"
Debug-Out "devProperty3($pos): '$($devProperty3[$pos])'" $DBG_DATA
}
}
}
}
}
}
}

# if ($ldIndex[$pos] -gt 0) {
$SVDevClass = "SVS_PGYStoragePoolCompositeExtent"
$DevData = Get-CimQuery -Query "SELECT * FROM $SVDevClass WHERE DeviceID Like '$($objItem.Name)%'" -Namespace $SVNamespace

$LDperCtrlPDArray[$pos] = @{}
$ld = 0
if ($script:WMIInstanceValid -eq $True) {
foreach ($devItem in $DevData) {
Debug-Out "\$($SVNamespace):$SVDevClass.ElementName: $($devItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDevClass.RaidLevel: $($devItem.RaidLevel)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDevClass.BlockSize: $($devItem.BlockSize)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDevClass.ConsumableBlocks: $($devItem.ConsumableBlocks)" $DBG_DESC
Debug-Out "\$($SVNamespace):$SVDevClass.NumberOfBlocks: $($devItem.NumberOfBlocks)" $DBG_DESC

if ($devItem.ElementName -ne "") {
$LDperCtrlNameArray[$pos,$ld] = "$($devItem.ElementName) ($pos/$ld)"
} else {
$LDperCtrlNameArray[$pos,$ld] = "Logical Drive ($pos/$ld)"
}
$LDperCtrlInfoArray[$pos,$ld] = $CIM_RAIDLevel[$devItem.RaidLevel]

$LDProperty1[$pos,$ld] = ConvertTo-MatchingUnit "$($devItem.NumberOfBlocks * $devItem.BlockSize)"
Debug-Out "LDProperty1($pos,$ld): '$($LDProperty1[$pos,$ld])'" $DBG_DATA

$DevData = @(Get-CimAssociatedInstance -InputObject $devItem)
if (-not ([string]::IsNullOrEmpty($DevData))) {
Debug-Out "Found $($DevData.Count) Associated Instances for 'SVS_PGYStoragePoolCompositeExtent ($($devItem.ElementName))'" $DBG_DATA
foreach ($devItem in $DevData) {
Debug-Out "$($devItem.CreationClassName) / $($devItem.ElementName) / $($devItem.Caption)" $DBG_DATA
}

$physSize = 0
$ldpd = 0
$LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"] = @{}
$LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["PD"] = @("") * $MaxPD
$LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["Instance"] = @("") * $MaxPD
foreach ($devItem in $DevData) {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).CreationClassName: $($devItem.CreationClassName)" $DBG_DESC

switch ("$($devItem.CreationClassName)") {
"SVS_PGYDiskExtent" {
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).ElementName: $($devItem.ElementName)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).DeviceID: $($devItem.DeviceID)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).BlockSize: $($devItem.BlockSize)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).ConsumableBlocks: $($devItem.ConsumableBlocks)" $DBG_DESC
Debug-Out "\$($SVNamespace):$($devItem.CreationClassName).NumberOfBlocks: $($devItem.NumberOfBlocks)" $DBG_DESC
$physSize += ($devItem.ConsumableBlocks * $devItem.BlockSize)
$LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["PD"][$ldpd] = "$($devItem.ElementName)"
Debug-Out " Associated Disk '$($devItem.ElementName)' at Ctrl $pos, LD '$($LDperCtrlNameArray[$pos,$ld])', index $($ldpd): '$($LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["PD"][$ldpd])', Size $($devItem.ConsumableBlocks * $devItem.BlockSize)" $DBG_INFO
$ldpd ++
}
}
}
}
$LDProperty2[$pos,$ld] = ConvertTo-MatchingUnit $physSize
Debug-Out "LDProperty2($pos,$ld): '$($LDProperty2[$pos,$ld])'" $DBG_DATA

Debug-Out "Log. Drive $pos/$($ld): $($LDperCtrlNameArray[$pos,$ld]) $($LDperCtrlInfoArray[$pos,$ld])" $DBG_INFO
$ldIndex[$pos]++
$ldIndexAll++
$ld++
}
}
# }
$ctrlIndex++
$pos++
}
}
} else {
if ($script:SVAgentRunning -eq $True) {
$ctrlIndex = Get-ScciData 0x2110 0 0 $script:Cabinet
Debug-Out "Number of RAID controllers: $ctrlIndex" $DBG_INFO

if ($ctrlIndex -gt 0) {
for ($pos=0; $pos -lt $ctrlIndex; $pos++) {
$strComponentValue = Get-ScciData 0x2111 0 $pos $script:Cabinet
if ($strComponentValue -ne "") {
$adapterNameArray[$pos] = $strComponentValue
} else {
$adapterNameArray[$pos] = "Adapter $pos"
}

$intComponentValue = Get-ScciData 0x2112 0 $pos $script:Cabinet
switch ($intComponentValue) {
0 { $adapterInfoArray[$pos] = "SCSI" }
1 { $adapterInfoArray[$pos] = "ATAPI" }
2 { $adapterInfoArray[$pos] = "PATA" }
3 { $adapterInfoArray[$pos] = "Firewire IEEE 1394" }
4 { $adapterInfoArray[$pos] = "SSA" }
5 { $adapterInfoArray[$pos] = "Fibre" }
6 { $adapterInfoArray[$pos] = "USB" }
7 { $adapterInfoArray[$pos] = "SATA" }
8 { $adapterInfoArray[$pos] = "SAS" }
9 { $adapterInfoArray[$pos] = "RAID" }
10 { $adapterInfoArray[$pos] = "MMC" }
11 { $adapterInfoArray[$pos] = "SD card bus" }
default { $adapterInfoArray[$pos] = $STATUS_UNKNOWN }
}
Debug-Out "RAID Controller $pos, Name $($adapterNameArray[$pos]), $($adapterInfoArray[$pos])" $DBG_INFO

$devProperty1[$pos] = Get-ScciProperty 0x211D 0 $pos $script:Cabinet "Vendor"
$devProperty2[$pos] = Get-ScciProperty 0x211D 0 $pos $script:Cabinet "SerialNumber"
if ($strComponentValue -ne "") { $devProperty2[$pos] = "N/A" }
$strComponentValue = Get-ScciProperty 0x211D 0 $pos $script:Cabinet "DriverName"
if ($strComponentValue -ne "") {
$intComponentValue = Get-ScciProperty 0x211D 0 $pos $script:Cabinet "DriverVersion"
$devProperty3[$pos] = "$strComponentValue, V$intComponentValue"
} else {
$devProperty3[$pos] = ""
}
$devProperty4[$pos] = Get-ScciProperty 0x211D 0 $pos $script:Cabinet "FirmwareVersion"
Debug-Out "devProperty1($pos): '$($devProperty1[$pos])'" $DBG_DATA
Debug-Out "devProperty2($pos): '$($devProperty2[$pos])'" $DBG_DATA
Debug-Out "devProperty3($pos): '$($devProperty3[$pos])'" $DBG_DATA
Debug-Out "devProperty4($pos): '$($devProperty4[$pos])'" $DBG_DATA

$pdIndex[$pos] = Get-ScciData 0x2130 $pos 0 $script:Cabinet
Debug-Out "Number of Phys. Disks on RAID Adapter $($adapterNameArray[$pos]): $($pdIndex[$pos])" $DBG_INFO
if ($pdIndex[$pos] -gt 0) {
for ($pd=0; $pd -lt $pdIndex[$pos]; $pd++) {
$strComponentValue = Get-ScciData 0x2133 $pos $pd $script:Cabinet
$intComponentValue = Get-ScciData 0x2135 $pos $pd $script:Cabinet
$intComponentValue = $intComponentValue * 1024 * 1024

if ($strComponentValue -ne "") {
$PDperCtrlNameArray[$pos,$pd] = "$strComponentValue ($pos/$pd)"
} else {
$PDperCtrlNameArray[$pos,$pd] = "Physical Disk ($pos/$pd)"
}

if ($intComponentValue -ne "") {
$PDperCtrlInfoArray[$pos,$pd] = ConvertTo-MatchingUnit $intComponentValue
}

$PDProperty1[$pos,$pd] = Get-ScciProperty 0x213D $pos $pd $script:Cabinet "FirmwareVersion"
$PDProperty2[$pos,$pd] = Get-ScciProperty 0x213D $pos $pd $script:Cabinet "Product"
$PDProperty3[$pos,$pd] = Get-ScciProperty 0x213D $pos $pd $script:Cabinet "SerialNumber"
$PDProperty4[$pos,$pd] = Get-ScciProperty 0x213D $pos $pd $script:Cabinet "Vendor"
Debug-Out "PDProperty1($pos,$pd): '$($PDProperty1[$pos,$pd])'" $DBG_DATA
Debug-Out "PDProperty2($pos,$pd): '$($PDProperty2[$pos,$pd])'" $DBG_DATA
Debug-Out "PDProperty3($pos,$pd): '$($PDProperty3[$pos,$pd])'" $DBG_DATA
Debug-Out "PDProperty4($pos,$pd): '$($PDProperty4[$pos,$pd])'" $DBG_DATA

Debug-Out "Phys. Disk $pos/$($pd): $($PDperCtrlNameArray[$pos,$pd]) $($PDperCtrlInfoArray[$pos,$pd])" $DBG_INFO
$pdIndexAll ++
}
}

$ldIndex[$pos] = Get-ScciData 0x2150 $pos 0 $script:Cabinet
$LDperCtrlPDArray[$pos] = 0
Debug-Out "Number of Log. Drives on RAID Adapter $($adapterNameArray[$pos]): $($ldIndex[$pos])" $DBG_INFO
if ($ldIndex[$pos] -gt 0) {
for ($ld=0; $ld -lt $ldIndex[$pos]; $ld++) {
$strComponentValue = Get-ScciData 0x2152 $pos $ld $script:Cabinet
$intComponentValue = Get-ScciData 0x2155 $pos $ld $script:Cabinet

if ($strComponentValue -ne "") {
$LDperCtrlNameArray[$pos,$ld] = "$strComponentValue ($pos/$ld)"
} else {
$LDperCtrlNameArray[$pos,$ld] = "Logical Drive ($pos/$ld)"
}

if ($intComponentValue -ne "") {
$LDperCtrlInfoArray[$pos,$ld] = $intComponentValue
}

$tempProperty = Get-ScciData 0x2153 $pos $ld $script:Cabinet
$tempStatus = ""
if ($tempProperty -is [system.array]) {
for ($j=0; $j -lt $tempProperty.Length; $j++) {
$tempStatus = "$('{0:X2}' -f $tempProperty[$j+1])$('{0:X2}' -f $tempProperty[$j])"
$tempStatus = [convert]::ToInt32($tempStatus, 16)
$j++
}
$LDProperty1[$pos,$ld] = ConvertTo-MatchingUnit "$($tempStatus * 1024 * 1024)"
} else {
$LDProperty1[$pos,$ld] = ConvertTo-MatchingUnit "$($tempProperty * 1024 * 1024)"
}
Debug-Out "LDProperty1($pos,$ld): '$($LDProperty1[$pos,$ld])'" $DBG_DATA

$tempProperty = Get-ScciData 0x2154 $pos $ld $script:Cabinet
$tempStatus = ""
if ($tempProperty -is [system.array]) {
for ($j=0; $j -lt $tempProperty.Length; $j++) {
$tempStatus = "$('{0:X2}' -f $tempProperty[$j+1])$('{0:X2}' -f $tempProperty[$j])"
$tempStatus = [convert]::ToInt32($tempStatus, 16)
$j++
}
$LDProperty2[$pos,$ld] = ConvertTo-MatchingUnit "$($tempStatus * 1024 * 1024)"
} else {
$LDProperty2[$pos,$ld] = ConvertTo-MatchingUnit "$($tempProperty * 1024 * 1024)"
}
Debug-Out "LDProperty2($pos,$ld): '$($LDProperty2[$pos,$ld])'" $DBG_DATA

Debug-Out "Log. Drive $pos/$($ld): $($LDperCtrlNameArray[$pos,$ld]) $($LDperCtrlInfoArray[$pos,$ld])" $DBG_INFO
$ldIndexAll ++
}
}
}
} else {
$ctrlIndex = 0
}
}
}
Debug-Out "Number of RAID Controllers: $ctrlIndex" $DBG_INFO
Debug-Out "Number of Log. Drives: $ldIndexAll" $DBG_INFO
Debug-Out "Number of Phys. Disks: $pdIndexAll" $DBG_INFO

$devType = @("") * 50
$devNo = @(0) * 50
for ($pos = 0; $pos -lt $ctrlIndex; $pos++) {
for ($ld = 0; $ld -lt $ldIndex[$pos]; $ld++) {
for ($index = 0; $index -lt 50; $index++) {
if ($devType[$index] -eq "") {
$devType[$index] = $LDperCtrlInfoArray[$pos,$ld]
$devNo[$index] = 1
break
} elseif ($LDperCtrlInfoArray[$pos,$ld] -eq $devType[$index]) {
$devNo[$index] = $devNo[$index] + 1
break
}
}
}
}
$ldInfos = ""
for ($i = 0; $i -lt 50; $i++) {
if ($devType[$i] -ne "") {
$ldInfos = "$ldInfos'$($devType[$i])': $($devNo[$i]), "
}
}
if ($ldInfos.Length -gt 2) {
$ldInfos = $ldInfos.Substring(0, $ldInfos.Length - 2)
}

$devType = @("") * 50
$devNo = @(0) * 50
for ($pos = 0; $pos -lt $ctrlIndex; $pos++) {
for ($pd = 0; $pd -lt $pdIndex[$pos]; $pd++) {
for ($index = 0; $index -lt 50; $index++) {
if ($devType[$index] -eq "") {
$devType[$index] = $PDperCtrlInfoArray[$pos,$pd]
$devNo[$index] = 1
break
} elseif ($PDperCtrlInfoArray[$pos,$pd] -eq $devType[$index]) {
$devNo[$index] = $devNo[$index] + 1
break
}
}
}
}
$pdInfos = ""
for ($i = 0; $i -lt 50; $i++) {
if ($devType[$i] -ne "") {
$pdInfos = "$pdInfos'$($devType[$i])': $($devNo[$i]), "
}
}
if ($pdInfos.Length -gt 2) {
$pdInfos = $pdInfos.Substring(0, $pdInfos.Length - 2)
}

$script:componentNames = "RAID Controllers: $ctrlIndex"
$script:componentInfos = "Logical Drives: $ldIndexAll"
if ($ldInfos -ne "") { $script:componentInfos = "$($script:componentInfos), $ldInfos" }
$script:componentInfos = "$($script:componentInfos); Physical Disks: $pdIndexAll"
if ($pdInfos -ne "") { $script:componentInfos = "$($script:componentInfos), $pdInfos" }
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($ctrlIndex -gt 0) {
if ($script:insideMP -eq $True) {
Debug-Out "Create RaidComponents instance: RaidComponents `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidComponents']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidComponents']$")
Add-ComponentData $oInst $RAIDSUBSYSTEM $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsRaid `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsRaid']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsRaid']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

Debug-Out "Create $SVRaidOverallState instance: SVRaidOverallState `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SVRaidOverallState']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SVRaidOverallState']$")
Add-OtherDeviceData $oInst $SVRaidOverallState $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

# *** loop though controllers
for ($pos = 0; $pos -lt $ctrlIndex; $pos++) {
Debug-Out "Create $($adapterNameArray[$pos]) instance: RaidController `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']$")
Add-RaidControllerData $oInst "RAID Controller $pos" $adapterNameArray[$pos] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/Type$" $adapterInfoArray[$pos] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/Type"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/Vendor$" $devProperty1[$pos] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/Vendor"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/SerialNumber$" $devProperty2[$pos] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/SerialNumber"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/Driver$" $devProperty3[$pos] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/Driver"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/FirmwareVersion$" $devProperty4[$pos] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidController']/FirmwareVersion"
$oDiscoveryData.AddInstance($oInst)

# *** handle physical disks per controller
if ($pdIndex[$pos] -gt 0) {
Debug-Out "Create $($script:ComponentsList[$PHYSICALDISK]) $pos instance: RaidPhysicalDisks `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisks']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisks']$")
Add-RaidDeviceGroupData $oInst "$($script:ComponentsList[$PHYSICALDISK]) $pos" $adapterNameArray[$pos] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

for ($i = 0; $i -lt $pdIndex[$pos]; $i++) {
Debug-Out "Create $($PDperCtrlNameArray[$pos,$i]) instance: RaidPhysicalDisk `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']$")
Add-RaidDeviceData $oInst "RAID Physical Disk $pos/$i" $adapterNameArray[$pos] $PDperCtrlNameArray[$pos,$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/Size$" $PDperCtrlInfoArray[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/Size"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/FirmwareRevision$" $PDProperty1[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/FirmwareRevision"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/ModelName$" $PDProperty2[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/ModelName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/SerialNumber$" $PDProperty3[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/SerialNumber"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/VendorName$" $PDProperty4[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidPhysicalDisk']/VendorName"
$oDiscoveryData.AddInstance($oInst)

if ($LDperCtrlPDArray[$pos] -ne 0) {
for ($ld = 0; $ld -lt $ldIndex[$pos]; $ld++) {
for ($ldpd = 0; $ldpd -lt $MaxPD; $ldpd++) {
if ("$($LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["PD"][$ldpd])" -ne "") {
if ("$($PDperCtrlNameArray[$pos,$i])".Contains($LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["PD"][$ldpd])) {
Debug-Out "-&gt; '$($PDperCtrlNameArray[$pos,$i])' ($pos/$ld/$ldpd)" $DBG_DATA
$LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["PD"][$ldpd] = "$($PDperCtrlNameArray[$pos,$i])"
$LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$ld])"]["Instance"][$ldpd] = $oInst
}
}
}
}
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$PHYSICALDISK])' on $($script:ComponentsList[$RAIDSUBSYSTEM]) $pos instance ($($adapterNameArray[$pos]))" $DBG_SCOM
}

# *** handle logical drives per controller
if ($ldIndex[$pos] -gt 0) {
Debug-Out "Create $($script:ComponentsList[$LOGICALDRIVE]) $pos instance: RaidLogicalDrives `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrives']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrives']$")
Add-RaidDeviceGroupData $oInst "$($script:ComponentsList[$LOGICALDRIVE]) $pos" $adapterNameArray[$pos] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

for ($i = 0; $i -lt $ldIndex[$pos]; $i++) {
Debug-Out "Create $($LDperCtrlNameArray[$pos,$i]) instance: RaidLogicalDrive `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']$")
Add-RaidDeviceData $oInst "RAID Logical Drive $pos/$i" $adapterNameArray[$pos] $LDperCtrlNameArray[$pos,$i] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']/Type$" $LDperCtrlInfoArray[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']/Type"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']/Size$" $LDProperty1[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']/Size"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']/PhysicalSize$" $LDProperty2[$pos,$i] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RaidLogicalDrive']/PhysicalSize"
$oDiscoveryData.AddInstance($oInst)

# create LD-PD relationships
if ($LDperCtrlPDArray[$pos] -ne 0) {
foreach ($disk in $LDperCtrlPDArray[$pos]["$($LDperCtrlNameArray[$pos,$i])"]) {
for ($ldpd = 0; $ldpd -lt $MaxPD; $ldpd++) {
if ("$($disk["PD"][$ldpd])" -ne "") {
Debug-Out " Add LD Relationship for Disk '$($disk["PD"][$ldpd])' (LD '$($LDperCtrlNameArray[$pos,$i])')" $DBG_INFO
$relationship = $oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.RAIDLogicalDriveReferencesPhysicalDisk']$")
$relationship.Source = $oInst
$relationship.Target = $disk["Instance"][$ldpd]
$oDiscoveryData.AddInstance($relationship)
}
}
}
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$LOGICALDRIVE])' on $($script:ComponentsList[$RAIDSUBSYSTEM]) $pos instance ($($adapterNameArray[$pos]))" $DBG_SCOM
}
}
}
} else {
Debug-Out "Did not find any components of type '$($script:ComponentsList[$RAIDSUBSYSTEM])'" $DBG_INFO
Debug-Out "Did not find any components of type '$($script:ComponentsList[$LOGICALDRIVE])'" $DBG_INFO
Debug-Out "Did not find any components of type '$($script:ComponentsList[$PHYSICALDISK])'" $DBG_INFO
}

#*** Other
#-----------------------------
$componentSubSystemType = $OTHER
Debug-Out "***** $($script:ComponentsList[$componentSubSystemType]) *****" $DBG_INFO

Clear-Status

if ($SVAgentVersion -ne "") {
if ($script:SVAgentRunning -eq $False) {
$script:componentNameArray[0] = $SVAgentOverallState
$script:componentInfoArray[0] = ""
$script:componentNameArray[1] = "Communication Monitor"
$script:componentInfoArray[1] = ""
$index = 3
} else {
$index = Get-SubsystemData $componentSubSystemType
}
Debug-Out "Number of Other components: $index" $DBG_INFO

$script:componentNames = "Other Components: $index"
Debug-Out "Discovered Components: $($script:componentNames)" $DBG_INFO
Debug-Out "Discovered Component Infos: $($script:componentInfos)" $DBG_INFO

if ($script:insideMP -eq $True) {
Debug-Out "Create $($ComponentsList[$componentSubSystemType]) instance: OtherComponents `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.OtherComponents']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.OtherComponents']$")
Add-ComponentData $oInst $componentSubSystemType $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)

Debug-Out "Create relationship ServerContainsOtherComponents `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsOtherComponents']$" $DBG_SCOM
$oRelationship = $oDiscoveryData.CreateRelationshipInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ServerContainsOtherComponents']$")
$oRelationship.Source = $oServer
$oRelationship.Target = $oInst
$oDiscoveryData.AddInstance($oRelationship)

if ($index -gt 0) {
Debug-Out "Create $($script:componentNameArray[0]) instance: SVOverallState `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SVOverallState']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SVOverallState']$")
Add-OtherDeviceData $oInst $script:componentNameArray[0] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)
}
if ($index -gt 1) {
Debug-Out "Create $($script:componentNameArray[1]) instance: CommunicationMonitor `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.CommunicationMonitor']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.CommunicationMonitor']$")
Add-OtherDeviceData $oInst $script:componentNameArray[1] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)
}
if ($index -gt 2) {
Debug-Out "Create $($script:componentNameArray[2]) instance: BiosSelftest `$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.BiosSelftest']$" $DBG_SCOM
$oInst = $oDiscoveryData.CreateClassInstance("`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.BiosSelftest']$")
Add-OtherDeviceData $oInst $script:componentNameArray[2] $PrincipalName $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
$oDiscoveryData.AddInstance($oInst)
}
}
}

#*** Send the data to OpsMgr
#------------------------------------------------
if ($script:insideMP -eq $True) {
Debug-Out "***** Return oDiscoveryData to OM; Normal exit *****" $DBG_INFO
$oDiscoveryData # Submit the data
}

Debug-Out "***** Normal end of script. *****" $DBG_INFO
exit 0
} # End of Main

#----------------------------------------------------------------

function Initialize-LogIniFile
{
Debug-Out "Start Initialize-LogIniFile" $DBG_INFO
$fileOK = $False
$pathOK = $False

$LogIniFilePath = "$($script:LogFileDir)\$SVISCOMLogIniName"
$LogIn_FilePath = "$($script:LogFileDir)\$SVISCOMLogIn_Name"

try {
if (Test-Path -Path $LogIn_FilePath -ErrorAction Stop) {
Debug-Out "$LogIn_FilePath is available." $DBG_INFO
$pathOK = $True

$inLines = Get-Content $LogIn_FilePath
foreach ($line in $inLines) {
if ($line -match $script:MPVersion -and $fileOK -eq $False) {
Debug-Out "Found $($script:MPVersion) in $LogIn_FilePath file." $DBG_INFO
$fileOK = $True
}
}
} else {
Debug-Out "IN_ file $LogIn_FilePath is not available." $DBG_INFO
if (Test-Path -Path $script:LogFileDir) {
Debug-Out "Folder $LogFileDir is available" $DBG_INFO
} else {
Debug-Out "Create folder $LogFileDir" $DBG_INFO
New-Item -Path $LogFileDir -ItemType Directory | Out-Null
}

if (! (Test-Path -Path $script:LogFileDir)) {
Debug-Out "Log file folder $LogFileDir could not be created. Abort logging to file." $DBG_INFO
$script:DebugFile = $False
} else {
$pathOK = $True
}
}
} catch {
Debug-Out "Could not access log file folder: $($script:LogFileDir). Abort Logging." $DBG_INFO
$script:DebugMode = $False
$script:DebugFile = $False
}

# we write a new SVISCOMLog.in_ and SVISCOMLog.ini file, every time the MP is changed to
# make sure all INI-Values are documented for use by the customer if anything changes.
if (($pathOK -eq $True) -and ($fileOK -eq $False)) {
# Ini File Array
$IniArray = @(
@("", "", @("","","",""), @("","","","")),
@("Server Discovery Section", $SEC_ServerDiscovery, @($STR_DBGMODE,$STR_OVERWRITE,$STR_DBGLEVEL,$STR_DBGTEST), @("True","True","","")),
@("Components Monitor Section", $SEC_ComponentsMonitor, @($STR_DBGMODE,$STR_OVERWRITE,$STR_DBGLEVEL,$STR_DBGTEST), @("True","True","","")),
@("Fibre Channel Event Monitor Section", $SEC_FCEvents, @($STR_DBGMODE,$STR_OVERWRITE,$STR_DBGLEVEL,$STR_DBGTEST), @("True","True","","")),
@("Reset PRIMERGY Server Data Section", $SEC_ResetPYServerData, @($STR_DBGMODE,$STR_OVERWRITE,$STR_DBGLEVEL,$STR_DBGTEST), @("True","True","","")),
@("Performance Monitor Section", $SEC_PerfMonMonitor, @($STR_DBGMODE,$STR_OVERWRITE,$STR_DBGLEVEL,$STR_DBGTEST), @("True","True","",""))
)

Debug-Out "write new $LogIn_FilePath file." $DBG_INFO
if (Test-Path -Path $LogIn_FilePath) {
Remove-Item -Path $LogIn_FilePath -Force | Out-Null
}
Write-LogIniFile $LogIn_FilePath $IniArray

if (Test-Path -Path $LogIniFilePath) {
Debug-Out "$LogIniFilePath is available." $DBG_INFO

# get current values of SVISCOMLog.ini
$var = Get-IniValue $LogIniFilePath $SEC_ServerDiscovery $STR_DBGMODE; if ("$var" -ne "") { $IniArray[1][3][0] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ServerDiscovery $STR_OVERWRITE; if ("$var" -ne "") { $IniArray[1][3][1] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ServerDiscovery $STR_DBGLEVEL; if ("$var" -ne "") { $IniArray[1][3][2] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ServerDiscovery $STR_DBGTEST; if ("$var" -ne "") { $IniArray[1][3][3] = $var }
Debug-Out "$($SEC_ServerDiscovery): $STR_DBGMODE $($IniArray[1][3][0]), $STR_OVERWRITE $($IniArray[1][3][1]), $STR_DBGLEVEL $($IniArray[1][3][2]), $STR_DBGTEST $($IniArray[1][3][3])" $DBG_DATA

$var = Get-IniValue $LogIniFilePath $SEC_ComponentsMonitor $STR_DBGMODE; if ("$var" -ne "") { $IniArray[2][3][0] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ComponentsMonitor $STR_OVERWRITE; if ("$var" -ne "") { $IniArray[2][3][1] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ComponentsMonitor $STR_DBGLEVEL; if ("$var" -ne "") { $IniArray[2][3][2] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ComponentsMonitor $STR_DBGTEST; if ("$var" -ne "") { $IniArray[2][3][3] = $var }
Debug-Out "$($SEC_ComponentsMonitor): $STR_DBGMODE $($IniArray[2][3][0]), $STR_OVERWRITE $($IniArray[2][3][1]), $STR_DBGLEVEL $($IniArray[2][3][2]), $STR_DBGTEST $($IniArray[2][3][3])" $DBG_DATA

$var = Get-IniValue $LogIniFilePath $SEC_FCEvents $STR_DBGMODE; if ("$var" -ne "") { $IniArray[3][3][0] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_FCEvents $STR_OVERWRITE; if ("$var" -ne "") { $IniArray[3][3][1] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_FCEvents $STR_DBGLEVEL; if ("$var" -ne "") { $IniArray[3][3][2] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_FCEvents $STR_DBGTEST; if ("$var" -ne "") { $IniArray[3][3][3] = $var }
Debug-Out "$($SEC_FCEvents): $STR_DBGMODE $($IniArray[3][3][0]), $STR_OVERWRITE $($IniArray[3][3][1]), $STR_DBGLEVEL $($IniArray[3][3][2]), $STR_DBGTEST $($IniArray[3][3][3])" $DBG_DATA

$var = Get-IniValue $LogIniFilePath $SEC_ResetPYServerData $STR_DBGMODE; if ("$var" -ne "") { $IniArray[4][3][0] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ResetPYServerData $STR_OVERWRITE; if ("$var" -ne "") { $IniArray[4][3][1] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ResetPYServerData $STR_DBGLEVEL; if ("$var" -ne "") { $IniArray[4][3][2] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_ResetPYServerData $STR_DBGTEST; if ("$var" -ne "") { $IniArray[4][3][3] = $var }
Debug-Out "$($SEC_ResetPYServerData): $STR_DBGMODE $($IniArray[4][3][0]), $STR_OVERWRITE $($IniArray[4][3][1]), $STR_DBGLEVEL $($IniArray[4][3][2]), $STR_DBGTEST $($IniArray[4][3][3])" $DBG_DATA

$var = Get-IniValue $LogIniFilePath $SEC_PerfMonMonitor $STR_DBGMODE; if ("$var" -ne "") { $IniArray[5][3][0] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_PerfMonMonitor $STR_OVERWRITE; if ("$var" -ne "") { $IniArray[5][3][1] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_PerfMonMonitor $STR_DBGLEVEL; if ("$var" -ne "") { $IniArray[5][3][2] = $var }
$var = Get-IniValue $LogIniFilePath $SEC_PerfMonMonitor $STR_DBGTEST; if ("$var" -ne "") { $IniArray[5][3][3] = $var }
Debug-Out "$($SEC_PerfMonMonitor): $STR_DBGMODE $($IniArray[5][3][0]), $STR_OVERWRITE $($IniArray[5][3][1]), $STR_DBGLEVEL $($IniArray[5][3][2]), $STR_DBGTEST $($IniArray[5][3][3])" $DBG_DATA

Debug-Out "write new $LogIniFilePath file." $DBG_INFO
if (Test-Path -Path $LogIniFilePath) {
Remove-Item -Path $LogIniFilePath -Force | Out-Null
}
Write-LogIniFile $LogIniFilePath $IniArray
}
}

Debug-Out "End Initialize-LogIniFile" $DBG_INFO
}

#----------------------------------------------------------------

function Write-LogIniFile
{
param (
$File,
$IniArray
)

Debug-Out "Write-LogIniFile: Write new '$File' file." $DBG_INFO

$versionLine = "; SVISCOM Debug INI file for Windows MP Version $($script:MPVersion)"
$commentSection = ";`r`n"+
"; With this file logging for all scripts within the management pack can be enabled.`r`n"+
"; Each of the Sections in this file represents a script.`r`n"+
"; DebugMode enables logging (true|yes|1) or `r`n"+
"; disables logging (false|no|0)`r`n"+
"; OverWrite defines continuous logging (false|no|0) or`r`n"+
"; single script run logging (true|yes|1)`r`n"+
";`r`n"+
"; Note: Continuous Logging logs continually forever!`r`n"+
"; Make sure to switch off (set to True) Continuous Logging`r`n"+
"; once the problem you were looking for was found!"

try {
New-Item -Path $File -ItemType File | Out-Null
Add-Content -Path $File -Value $versionLine
Add-Content -Path $File -Value $commentSection

$j = 0
foreach ($IniVal in $IniArray) {
# we skip the FileSize stuff. admins are wily enough to know themselves when they log continously.
if ($j -eq 0) { $j++; continue }
Add-Content -Path $File -Value ""
Add-Content -Path $File -Value "; $($IniVal[0])"
Add-Content -Path $File -Value "$($IniVal[1])"

for ($i=0; $i -lt 5; $i++) {
if ($j -eq 0 -and $i -eq 0) {
if ("$($IniVal[3][$i])" -ne "") {
Add-Content -Path $File -Value "$($IniVal[2][$i])=$($IniVal[3][$i])"
} else {
Add-Content -Path $File -Value "; $($IniVal[2][$i])=10GB"
}
} else {
if ("$($IniVal[3][$i])" -ne "") {
Add-Content -Path $File -Value "$($IniVal[2][$i])=$($IniVal[3][$i])"
}
}
}
$j++
}
} catch {
Debug-Out "Could not write new '$File' files." $DBG_INFO
}
}

#----------------------------------------------------------------

function Get-SubsystemData
{
param (
$SubSystemNumber
)

$componentCount = 0
$script:componentCountEmpty = 0

if ($script:CIMProvider -eq $True) {
$SVAgentClass = "SVS_PGYHealthStateComponent"
$SubSystem = $cimHealthStateSubsystem[$SubSystemNumber]

if ($SubSystemNumber -eq $OTHER) {
Debug-Out "Get-SubsystemData for '$SubSystem'" $DBG_DATA
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass WHERE Caption='$Subsystem'" -Namespace $svsNS

if ($script:WMIInstanceValid -eq $True) {
foreach ($objItem in $CimData) {
Debug-Out "\$($svsNS):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
$script:componentNameArray[$componentCount] = $SVAgentOverallState
Debug-Out "Component $($componentCount): '$($script:componentNameArray[$componentCount])'" $DBG_DATA
$componentCount ++

$script:componentNameArray[$componentCount] = "Communication Monitor"
Debug-Out "Component $($componentCount): '$($script:componentNameArray[$componentCount])'" $DBG_DATA
$componentCount ++
}
}

$SubSystem = $script:cimHealthStateSubsystem[$SELFTEST]
}

Debug-Out "Get-SubsystemData for '$SubSystem'" $DBG_DATA
$CimData = Get-CimQuery -Query "SELECT * FROM $SVAgentClass WHERE Caption LIKE '%$SubSystem%'" -Namespace $svsNS

$DevCabinet = $script:Cabinet
if ($script:WMIInstanceValid -eq $True) {
$index = 0
foreach ($objItem in $CimData) {
if ($SubSystemNumber -eq $OTHER) {
Debug-Out "\$($svsNS):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($svsNS):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
$script:componentNameArray[$componentCount] = $objItem.ElementName
Debug-Out "Component $($componentCount): '$($script:componentNameArray[$componentCount])', $($objItem.HealthState) " $DBG_DATA
$componentCount ++ # we only count existing $components
}
# It is an actual component if the InstanceID is something like '0-0-0-0'
# Except for PowerConsumption where we need to request the '0-0-0' Level
Debug-Out "\$($svsNS):$SVAgentClass.Caption: $($objItem.Caption)" $DBG_DESC
Debug-Out "\$($svsNS):$SVAgentClass.InstanceID: $($objItem.InstanceID)" $DBG_DESC

$idLevel = ($objItem.InstanceID -Split "-").Length
if (($idLevel -gt 3) -or (($SubSystemNumber -eq $POWERCONSUMP) -and ($idLevel -gt 2))) {
Debug-Out "\$($svsNS):$SVAgentClass.Presence: $($objItem.Presence)" $DBG_DESC
Debug-Out "\$($svsNS):$SVAgentClass.ElementName: $($objItem.ElementName)" $DBG_DESC
Debug-Out "\$($svsNS):$SVAgentClass.HealthState: $($objItem.HealthState)" $DBG_DESC
Debug-Out "\$($svsNS):$SVAgentClass.AssociationKey: $($objItem.AssociationKey)" $DBG_DESC
if (($SubSystemNumber -eq $FANS) -or ($SubSystemNumber -eq $TEMPERATURE) -or ($SubSystemNumber -eq $POWERSUPPLY)) {
if ($objItem.AssociationKey.Length -ge 9) {
$DevIndex = $objItem.AssociationKey.Substring(5, 4)
$DevIndex = [convert]::ToInt32($DevIndex, 16)
if ($objItem.AssociationKey.Length -ge 19) {
$DevCabinet = $objItem.AssociationKey.Substring(15, 4)
$DevCabinet = [convert]::ToInt32($DevCabinet, 16)
}
}
$script:componentNameArray[$componentCount] = "$DevCabinet/$DevIndex $($objItem.ElementName)"
} else {
$script:componentNameArray[$componentCount] = $objItem.ElementName
}
if ($objItem.Presence -ne 2) {
Debug-Out "Component $($index): '$($script:componentNameArray[$componentCount])', $($objItem.HealthState)" $DBG_DATA
$componentCount ++ # we only count existing $components
} else {
$script:componentCountEmpty ++
$script:componentNameArray[$componentCount] = ""
}
$index ++
}
}
}
} else {
if ($script:SVAgentRunning -eq $True) {
$SubSystem = $scciHealthStateSubsystem[$SubSystemNumber]
Debug-Out "Get-SubsystemData for '$SubSystem'" $DBG_DATA
$scciText = $SubSystem -Split " - "

if ($SubSystemNumber -eq $OTHER) {
$script:componentNameArray[$componentCount] = $SVAgentOverallState
Debug-Out "Component $($componentCount): '$($script:componentNameArray[$componentCount])'" $DBG_DATA
$componentCount ++ # we only count existing $components

$script:componentNameArray[$componentCount] = "Communication Monitor"
Debug-Out "Component $($componentCount): '$($script:componentNameArray[$componentCount])'" $DBG_DATA
$componentCount ++

$scciText = $script:scciHealthStateSubsystem[$SELFTEST] -Split " - "
}

$sysNo = Get-ScciData 0x2300 0 0 $script:Cabinet
Debug-Out "Got $sysNo Status Tree Subsystems" $DBG_DESC
for ($i = 0; $i -lt $sysNo; $i++) {
$scciName = Get-ScciData 0x2302 $i 0 $script:Cabinet
Debug-Out "$i Subsystem: $scciName" $DBG_DESC
if ($scciText[0] -eq $scciName) {

$subsysNo = Get-ScciData 0x2305 $i 0 $script:Cabinet
Debug-Out " Got $subsysNo Status Tree Subsys Classes" $DBG_DESC
for ($j = 0; $j -lt $subsysNo; $j++) {
$scciName = Get-ScciData 0x2307 $i $j $script:Cabinet
Debug-Out " $i/$j SubsystemClass: $scciName" $DBG_DESC
if ($scciText[1] -eq $scciName) {

$subsyscompWord = $i * 0x10000 + $j
$subsyscompNo = Get-ScciData 0x2320 $subsyscompWord 0 $script:Cabinet
Debug-Out " Got $subsyscompNo Status Tree Subsys Components" $DBG_DESC
$cab = 0
$l = 0
for ($k = 0; $k -lt $subsyscompNo; $k++) {
if ($k -gt $cMAXINDEX) {
Debug-Out "Max. no. of '$scciName' instances ($cMAXINDEX) reached/exceeded" $DBG_DESC
break
}

$scciState = $Null
$Status = $script:oSwitch.ScciQuery(0x2322, $subsyscompWord, $l, $script:CabinetArray[$cab], 0, [REF]$scciState, 0)

if ($Status -ne 0) {
Debug-Out "oSwitch: No Data for opCode=0x2322 opCodeExt=0x$('{0:X}' -f $subsyscompWord) objIndex=$l cabID=$($script:CabinetArray[$cab])" $DBG_DESC
$cab = $cab + 1

# abort if there is no next cabinet
if ($Null -eq $script:CabinetArray[$cab]) { break }

$l = 0
$Status = $script:oSwitch.ScciQuery(0x2322, $subsyscompWord, $l, $script:CabinetArray[$cab], 0, [REF]$scciState, 0)
if ($Status -ne 0) {
Debug-Out "oSwitch: No Data for opCode=0x2322 opCodeExt=0x$('{0:X}' -f $subsyscompWord) objIndex=$l cabID=$($script:CabinetArray[$cab])" $DBG_DESC
} else {
Debug-Out "oSwitch: opCode=0x2322 opCodeExt=0x$('{0:X}' -f $subsyscompWord) objIndex=$l cabID=$($script:CabinetArray[$cab]) -&gt; scciValue = '$scciState'" $DBG_DESC
}
} else {
Debug-Out "oSwitch: opCode=0x2322 opCodeExt=0x$('{0:X}' -f $subsyscompWord) objIndex=$l cabID=$($script:CabinetArray[$cab]) -&gt; scciValue = '$scciState'" $DBG_DESC
}

$scciDesc = Get-ScciData 0x2324 $subsyscompWord $l $script:CabinetArray[$cab]

if (($SubSystemNumber -eq $FANS) -or ($SubSystemNumber -eq $TEMPERATURE) -or ($SubSystemNumber -eq $POWERSUPPLY)) {
$script:componentNameArray[$componentCount] = "$($script:CabinetArray[$cab])/$l $scciDesc"
} elseif ($SubSystemNumber -eq $OTHER) {
$script:componentNameArray[$componentCount] = Get-ScciData 0x2308 $i $j $cab
} elseif ($SubSystemNumber -eq $POWERCONSUMP) {
$script:componentNameArray[$componentCount] = "Power Level"
} else {
$script:componentNameArray[$componentCount] = $scciDesc
}

if (($scciState -lt 0) -or ($scciState -gt 5)) {
$Status = $STATUS_INVALID
} else {
$Status = $scciHealthStateString[$scciState]
}

if ($Status -ne $STATUS_NOTPRESENT) {
Debug-Out " $i/$j/$($k): SubSystemComponent: '$($script:componentNameArray[$componentCount])', '$scciState'" $DBG_DATA
$componentCount ++ # we only count existing $components
} else {
$script:componentCountEmpty ++ # we only count existing $components
$script:componentNameArray[$componentCount] = ""
}
$l++
}
$j = $subsysNo
$i = $sysNo
}
}
}
}
} else {
Debug-Out "Agent is *** NOT *** running ..." $DBG_DATA
}
}

return $componentCount
}

#----------------------------------------------------------------

function Add-MPElement
{
param (
$oInst,
$elementName,
$elementValue,
$elementType
)

Debug-Out "Add-MPElement: '$elementName' = '$elementValue' : '$elementType'" $DBG_SCOM
$oInst.AddProperty("$elementName", "$elementValue")
}

#----------------------------------------------------------------

function Add-ObjectData
{
param (
$oInst,
$displayName,
$PrincipalName
)

Add-MPElement $oInst "`$MPElement[Name='System!System.Entity']/DisplayName$" $displayName "MPElement[Name='System!System.Entity']/DisplayName"
Add-MPElement $oInst "`$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$" $PrincipalName "MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName"
}

#----------------------------------------------------------------

function Add-SoftwareData
{
param (
$oInst,
$displayName,
$swName,
$swVersion,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName
)

Add-ObjectData $oInst $displayName $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName"
Add-MPElement $oInst "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.ManagementSoftware']/Version$" $swVersion "MPElement[Name='FTSLIB!Fujitsu.ServerView.ManagementSoftware']/Version"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/Devices$" $swName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/Devices"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/ServerName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/ServerName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/NetworkName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/BMCAddrIPv4$" $BMCIPv4Addr "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/BMCAddrIPv4"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/BMCAddr$" $iRMCDNSName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/BMCAddr"
}


#----------------------------------------------------------------

function Add-BasicComponentData
{
param (
$oInst,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/ServerName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/ServerName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/BMCAddrIPv4$" $BMCIPv4Addr "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/BMCAddrIPv4"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/BMCAddr$" $iRMCDNSName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/BMCAddr"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/MonitoringAgents$" $MonitoringAgents "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/MonitoringAgents"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/RaidManager$" $RaidManager "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.Component']/RaidManager"
}

#----------------------------------------------------------------

function Add-SoftwareVersionData
{
param (
$oInst,
$deviceName,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $deviceName $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ManagementClientSoftware']/NetworkName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName"
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.OtherComponent']/Device$" $deviceName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.OtherComponent']/Device"
}

#----------------------------------------------------------------

function Add-ComponentData
{
param (
$oInst,
$componentSubSystemType,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $ComponentsList[$componentSubSystemType] $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.HealthCollection']/Devices$" $componentNames "MPElement[Name='FTSLIB!Fujitsu.ServerView.HealthCollection']/Devices"
Add-MPElement $oInst "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.HealthCollection']/DevicesInfo$" $componentInfos "MPElement[Name='FTSLIB!Fujitsu.ServerView.HealthCollection']/DevicesInfo"
Add-MPElement $oInst "`$MPElement[Name='FTSLIB!Fujitsu.ServerView.HealthCollection']/ServerName$" $script:TargetComputer "MPElement[Name='FTSLIB!Fujitsu.ServerView.HealthCollection']/ServerName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/BMCAddrIPv4$" $BMCIPv4Addr "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/BMCAddrIPv4"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/BMCAddr$" $iRMCDNSName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/BMCAddr"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/ComponentID$" $ComponentsStateList[$componentSubSystemType] "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/ComponentID"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/MonitoringAgents$" $MonitoringAgents "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/MonitoringAgents"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/RaidManager$" $RaidManager "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/RaidManager"
}

#----------------------------------------------------------------

function Add-ComponentHealthData
{
param (
$oInst,
$deviceName,
$MonitoringAgents,
$RaidManager
)

Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentHealth']/Device$" $deviceName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentHealth']/Device"
# obsolete - obsolete - obsolete
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentHealth']/MonitoringAgents$" $MonitoringAgents "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentHealth']/MonitoringAgents"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentHealth']/RaidManager$" $RaidManager "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentHealth']/RaidManager"
# obsolete - obsolete - obsolete
}

#----------------------------------------------------------------

function Add-SimpleDeviceData
{
param (
$oInst,
$deviceName,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $deviceName $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName"
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-ComponentHealthData $oInst $deviceName $MonitoringAgents $RaidManager
}

#----------------------------------------------------------------

function Add-OtherDeviceData
{
param (
$oInst,
$deviceName,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $deviceName $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName"
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.OtherComponent']/Device$" $deviceName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.OtherComponent']/Device"
}

#----------------------------------------------------------------

function Add-RaidControllerData
{
param (
$oInst,
$displayName,
$deviceName,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $displayName $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName"
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentBundleHealth']/Device$" $deviceName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentBundleHealth']/Device"
}

#----------------------------------------------------------------

function Add-RaidDeviceGroupData
{
param (
$oInst,
$displayName,
$deviceName,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $displayName $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName"
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentBundleHealth']/Device$" $deviceName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentBundleHealth']/Device"
}

#----------------------------------------------------------------

function Add-RaidDeviceData
{
param (
$oInst,
$displayname,
$adapterName,
$deviceName,
$PrincipalName,
$BMCIPv4Addr,
$iRMCDNSName,
$MonitoringAgents,
$RaidManager
)

Add-ObjectData $oInst $displayname $PrincipalName
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.HealthCollection']/NetworkName"
Add-BasicComponentData $oInst $BMCIPv4Addr $iRMCDNSName $MonitoringAgents $RaidManager
Add-ComponentHealthData $oInst $deviceName $MonitoringAgents $RaidManager
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName$" $script:TargetComputer "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.SimpleCollection']/NetworkName"
Add-MPElement $oInst "`$MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentBundleHealth']/Device$" $adapterName "MPElement[Name='Fujitsu.Servers.PRIMERGY.Windows.ComponentBundleHealth']/Device"
}

#................................................................

#-------------------------------------------------------------------
# SCOM.ps1
#-------------------------------------------------------------------

Set-Variable -Name cMAXINDEX -Option Constant -Value 196
$script:componentNameArray = @("") * $cMAXINDEX
$script:componentStatusArray = @("") * $cMAXINDEX
$script:componentInfoArray = @("") * $cMAXINDEX
$script:componentName = ""
$script:componentStatus = ""
$script:componentInfo = ""
$script:componentHealth = ""
$script:componentCountEmpty = ""

Set-Variable -Name PROCESSOR -Option Constant -Value 0
Set-Variable -Name MEMORY -Option Constant -Value 1
Set-Variable -Name STORAGE -Option Constant -Value 2
Set-Variable -Name NETWORK -Option Constant -Value 3
Set-Variable -Name MGMTCTRL -Option Constant -Value 4
Set-Variable -Name FANS -Option Constant -Value 5
Set-Variable -Name TEMPERATURE -Option Constant -Value 6
Set-Variable -Name VOLTAGES -Option Constant -Value 7
Set-Variable -Name POWERSUPPLY -Option Constant -Value 8
Set-Variable -Name POWERCONSUMP -Option Constant -Value 9
Set-Variable -Name RAIDSUBSYSTEM -Option Constant -Value 10
Set-Variable -Name PHYSICALDISK -Option Constant -Value 11
Set-Variable -Name LOGICALDRIVE -Option Constant -Value 12
Set-Variable -Name DRIVERMONITOR -Option Constant -Value 13 # currently not supported subsystem
Set-Variable -Name PCISLOTS -Option Constant -Value 14 # currently not supported subsystem
Set-Variable -Name OTHER -Option Constant -Value 15 # make sure this is the last subsystem
# continue with specific components
Set-Variable -Name SVOVERALL -Option Constant -Value 16
Set-Variable -Name SVVERSION -Option Constant -Value 17
Set-Variable -Name SELFTEST -Option Constant -Value 18
Set-Variable -Name TPMMODULE -Option Constant -Value 19
Set-Variable -Name RAIDOVERALL -Option Constant -Value 20
Set-Variable -Name RAIDVERSION -Option Constant -Value 21 # make sure this is the last component

$script:ComponentsList = @("Processors", "Memory", "Storage", "Networks (Ethernet)", "Management Controller",
"Fans (Cooling)", "Temperatures", "Voltages", "Power Supplies", "Power Consumption",
"RAID Subsystem", "RAID Physical Disks", "RAID Logical Drives", "Driver Monitor", "PCI Slots", "Other Components"
"SV OverallState", "SV Agents Version", "Bios Selftest", "TPM Module", "Raid OverallState", "Raid Version")
$script:ComponentsStateList = @("Processors", "Memory", "Storage", "Networks", "ManagementController",
"Fans", "TemperatureSensors", "VoltageSensors", "PowerSupplies", "PowerConsumption",
"RaidSubsystem", "RaidPhysicalDisks", "RaidLogicalDrives", "DriverMonitor", "PCISlots", "OtherComponents",
"SVOverallState", "SVAgentsVersion", "BiosSelftest", "TPMModule", "RaidOverallState", "RaidVersion")
$script:ComponentsPYServerData = @("") * ($OTHER + 1)
$script:ComponentsPYServerDataValid = @("") * ($OTHER + 1)

$script:cimHealthStateSubsystem = @("") * ($RAIDVERSION + 1)
$script:cimHealthStateSubsystem[$PROCESSOR] = "System Processors"
$script:cimHealthStateSubsystem[$MEMORY] = "Memory Modules"
$script:cimHealthStateSubsystem[$STORAGE] = "Mass Storage Adapters"
$script:cimHealthStateSubsystem[$NETWORK] = "Network"
$script:cimHealthStateSubsystem[$MGMTCTRL] = "" # no SVAgent State available
$script:cimHealthStateSubsystem[$FANS] = "Fans"
$script:cimHealthStateSubsystem[$TEMPERATURE] = "Temperature"
$script:cimHealthStateSubsystem[$VOLTAGES] = "System Board Voltages"
$script:cimHealthStateSubsystem[$POWERSUPPLY] = "Power Supply"
$script:cimHealthStateSubsystem[$POWERCONSUMP] = "Power Level"
$script:cimHealthStateSubsystem[$RAIDSUBSYSTEM] = "ServerView RAID System"
$script:cimHealthStateSubsystem[$PHYSICALDISK] = "RAID Physical disks"
$script:cimHealthStateSubsystem[$LOGICALDRIVE] = "RAID Logical drives"
$script:cimHealthStateSubsystem[$DRIVERMONITOR] = "Monitored Components"
$script:cimHealthStateSubsystem[$PCISLOTS] = "PCI Slots"
$script:cimHealthStateSubsystem[$OTHER] = "System"
$script:cimHealthStateSubsystem[$SVOVERALL] = ""
$script:cimHealthStateSubsystem[$SVVERSION] = ""
$script:cimHealthStateSubsystem[$SELFTEST] = "BIOS Selftest"
$script:cimHealthStateSubsystem[$TPMMODULE] = "Trusted Platform Module"
$script:cimHealthStateSubsystem[$RAIDOVERALL] = ""
$script:cimHealthStateSubsystem[$RAIDVERSION] = ""

$script:scciHealthStateSubsystem = @("") * ($RAIDVERSION + 1)
$script:scciHealthStateSubsystem[$PROCESSOR] = "Systemboard - SvCPUs"
$script:scciHealthStateSubsystem[$MEMORY] = "Systemboard - SvMemModules"
$script:scciHealthStateSubsystem[$STORAGE] = "MassStorage - SvMassStorageAdapters"
$script:scciHealthStateSubsystem[$NETWORK] = "Network - SvNetworkAdapters"
$script:scciHealthStateSubsystem[$MGMTCTRL] = "" # no SVAgent State available
$script:scciHealthStateSubsystem[$FANS] = "Environment - SvFans"
$script:scciHealthStateSubsystem[$TEMPERATURE] = "Environment - SvTempSensors"
$script:scciHealthStateSubsystem[$VOLTAGES] = "Systemboard - SvVoltages"
$script:scciHealthStateSubsystem[$POWERSUPPLY] = "PowerSupply - SvPowerSupplies"
$script:scciHealthStateSubsystem[$POWERCONSUMP] = "PowerSupply - SvPowerLevel"
$script:scciHealthStateSubsystem[$RAIDSUBSYSTEM] = "MassStorage - SvRaidAura"
$script:scciHealthStateSubsystem[$PHYSICALDISK] = "MassStorage - SvRaidPhysicalDisks"
$script:scciHealthStateSubsystem[$LOGICALDRIVE] = "MassStorage - SvRaidLogicalDrives"
$script:scciHealthStateSubsystem[$DRIVERMONITOR] = "DrvMonitor - SvMonitoredComponents"
$script:scciHealthStateSubsystem[$PCISLOTS] = "Systemboard - SvPCISlots"
$script:scciHealthStateSubsystem[$OTHER] = "System"
$script:scciHealthStateSubsystem[$SVOVERALL] = ""
$script:scciHealthStateSubsystem[$SVVERSION] = ""
$script:scciHealthStateSubsystem[$SELFTEST] = "Systemboard - SvBIOS"
$script:scciHealthStateSubsystem[$TPMMODULE] = "Systemboard - SvTPM"
$script:scciHealthStateSubsystem[$RAIDOVERALL] = ""
$script:scciHealthStateSubsystem[$RAIDVERSION] = ""

$script:DeviceList = @("") * ($RAIDVERSION + 1)
$script:DeviceList[$PROCESSOR] = "Processor"
$script:DeviceList[$MEMORY] = "MemoryModule"
$script:DeviceList[$STORAGE] = "StorageDisk"
$script:DeviceList[$NETWORK] = "NetworkDevice"
$script:DeviceList[$MGMTCTRL] = "ManagementController"
$script:DeviceList[$FANS] = "Fan"
$script:DeviceList[$TEMPERATURE] = "TemperatureSensor"
$script:DeviceList[$VOLTAGES] = "VoltageSensor"
$script:DeviceList[$POWERSUPPLY] = "PowerSupply"
$script:DeviceList[$POWERCONSUMP] = "PowerConsumption"
$script:DeviceList[$RAIDSUBSYSTEM] = "RaidController"
$script:DeviceList[$PHYSICALDISK] = "RaidPhysicalDisk"
$script:DeviceList[$LOGICALDRIVE] = "RaidLogicalDrive"
$script:DeviceList[$DRIVERMONITOR] = "DriverMonitor"
$script:DeviceList[$PCISLOTS] = "PCISlots"
$script:DeviceList[$OTHER] = "OtherComponent"
$script:DeviceList[$SVOVERALL] = "SVOverallState"
$script:DeviceList[$SVVERSION] = "ServerViewAgentsVersion"
$script:DeviceList[$SELFTEST] = "BiosSelftest"
$script:DeviceList[$TPMMODULE] = "TrustedPlatformModule"
$script:DeviceList[$RAIDOVERALL] = "SVRaidOverallState"
$script:DeviceList[$RAIDVERSION] = "ServerViewRaidVersion"

$script:componentCommunicationStatusArray = @("") * $RAIDVERSION
$script:componentCommunicationReasonArray = @("") * $RAIDVERSION

Set-Variable -Name STATUS_NONE -Option Constant -Value "None"
Set-Variable -Name STATUS_ERROR -Option Constant -Value "Error"
Set-Variable -Name STATUS_DEGRADED -Option Constant -Value "Degraded"
Set-Variable -Name STATUS_OK -Option Constant -Value "OK"
Set-Variable -Name STATUS_UNKNOWN -Option Constant -Value "Unknown"
Set-Variable -Name STATUS_NOTPRESENT -Option Constant -Value "Not Present"
Set-Variable -Name STATUS_NOTMANAGEABLE -Option Constant -Value "Not Manageable"
Set-Variable -Name STATUS_INVALID -Option Constant -Value "Invalid"
Set-Variable -Name STATUS_COMMERR -Option Constant -Value "Communication Error"
Set-Variable -Name STATUS_NOSTATE -Option Constant -Value "No State"

$script:CIM_HealthState = @($STATUS_UNKNOWN) * 26
$script:CIM_HealthState[0] = $STATUS_UNKNOWN # Unknown
$script:CIM_HealthState[5] = $STATUS_OK # OK
$script:CIM_HealthState[10] = $STATUS_DEGRADED # Minor Failure
$script:CIM_HealthState[15] = $STATUS_DEGRADED # Major Failure
$script:CIM_HealthState[20] = $STATUS_ERROR # Critical Failure
$script:CIM_HealthState[25] = $STATUS_ERROR # Non-recoverable Error

$script:scciHealthStateString = @("") * 7
$script:scciHealthStateString[0] = $STATUS_UNKNOWN
$script:scciHealthStateString[1] = $STATUS_OK
$script:scciHealthStateString[2] = $STATUS_DEGRADED
$script:scciHealthStateString[3] = $STATUS_ERROR
$script:scciHealthStateString[4] = $STATUS_NOTPRESENT
$script:scciHealthStateString[5] = $STATUS_NOTMANAGEABLE
$script:scciHealthStateString[6] = $STATUS_INVALID

Set-Variable -Name ERROR_EVENT -Option Constant -Value 1
Set-Variable -Name WARNING_EVENT -Option Constant -Value 2
Set-Variable -Name INFORMATIONAL_EVENT -Option Constant -Value 4

#-------------------------------------------------------------------

function Write-ScriptEvent
{
param (
$scomAPI,
$EventID,
$EventType,
$sMessage
)

switch ($EventType) {
$ERROR_EVENT { Debug-Out "$($MPScript): ERROR_EVENT_$($EventID):`r`n$sMessage" $DBG_INFO }
$WARNING_EVENT { Debug-Out "$($MPScript): WARNING_EVENT_$($EventID):`r`n$sMessage" $DBG_INFO }
$INFORMATIONAL_EVENT { Debug-Out "$($MPScript): INFORMATIONAL_EVENT_$($EventID):`r`n$sMessage" $DBG_INFO }
}

if ($script:insideMP -eq $True) {
if ($isNano -eq $False) {
$scomAPI.LogScriptEvent($MPScript, $EventID, $EventType, $sMessage)
}
}
}

#----------------------------------------------------------------
# Re-initialise component names, info, status

function Clear-Status
{
$script:componentStatusArray = @("") * $cMAXINDEX
$script:componentNameArray = @("") * $cMAXINDEX
$script:componentInfoArray = @("") * $cMAXINDEX

$script:componentStatus = ""
$script:componentNames = ""
$script:componentInfos = ""
}

#................................................................

#-------------------------------------------------------------------
# DataRequest.ps1
#-------------------------------------------------------------------

Set-Variable -Name SVAGENTVERSION_MIN -Option Constant -Value "7.00.00"
Set-Variable -Name SVCIMVERSION_MIN -Option Constant -Value "8.00.00"
Set-Variable -Name CIMRAID_AGENTS_MIN -Option Constant -Value "8.00.00"

Set-Variable -Name SVRAIDVERSION_BASE -Option Constant -Value "3.1.4"
Set-Variable -Name SVRAIDVERSION_MIN -Option Constant -Value "6.0.3"
Set-Variable -Name CIMRAID_SVRAID_MIN -Option Constant -Value "6.4.11"

Set-Variable -Name SCCISLEEPTIME -Option Constant -Value 100
Set-Variable -Name wmiRetries -Option Constant -Value 5
Set-Variable -Name waitTimeMin -Option Constant -Value 100
Set-Variable -Name waitTimeMax -Option Constant -Value 1000

Set-Variable -Name cimv2NS -Option Constant -Value "root\cimv2"
Set-Variable -Name svsNS -Option Constant -Value "root\svs"

Set-Variable -Name IPMI_NETFN_APP -Option Constant -Value 0x06
Set-Variable -Name IPMI_NETFN_OEM_WITH_IANA -Option Constant -Value 0x2E
# IPMI NetFn Application (6) Command definitions
Set-Variable -Name IPMI_APP_GET_DEVICE_ID -Option Constant -Value 0x01
Set-Variable -Name IPMI_APP_GET_SELF_TEST_RESULTS -Option Constant -Value 0x04

$script:WMIInstanceValid = $False
$script:oSwitch = $Null

#-------------------------------------------------------------------

# request CIM Data
function Get-CimData
{
param (
[string]$Class,
[string]$Namespace
)

$script:WMIInstanceValid = $False
try {
if ($PSVersion.Major -ge 4) {
Debug-Out "Get-CimInstance -Class $Class -Namespace $Namespace" $DBG_DESC
$WmiData = @(Get-CimInstance -Class $Class -Namespace $Namespace -ErrorAction Stop)
} else {
Debug-Out "Get-WMIObject -Class $Class -Namespace $Namespace" $DBG_DESC
$WmiData = @(Get-WMIObject -Class $Class -Namespace $Namespace -ErrorAction Stop)
}
$WmiObjCount = $WmiData.Count

if ($WmiObjCount -ne 0) {
$script:WMIInstanceValid = $True
Debug-Out "'$Class' successfully delivered $WmiObjCount objects" $DBG_DESC
} else {
$script:WMIInstanceValid = $True
Debug-Out "'$Query' was successful but did not deliver any data. Reset WmiData object." $DBG_DESC
$WmiData = $Null
}
} catch [Exception] {
Debug-Out "Exception when requesting '$Class' from '$Namespace'." $DBG_DESC
Debug-Out "ErrorMessage: $($_.Exception.Message)" $DBG_DESC
}

return $WmiData
}

#----------------------------------------------------------------

# query CIM Data
function Get-CimQuery
{
param (
[string]$Query,
[string]$Namespace
)

$script:WMIInstanceValid = $False
try {
if ($PSVersion.Major -ge 4) {
Debug-Out "Get-CimInstance -Query $Query -Namespace $Namespace" $DBG_DESC
$WmiData = @(Get-CimInstance -Query $Query -Namespace $Namespace -ErrorAction Stop)
} else {
Debug-Out "Get-WMIObject -Query '$Query' -Namespace '$Namespace'" $DBG_DESC
$WmiData = @(Get-WMIObject -Query $Query -Namespace $Namespace -ErrorAction Stop)
}
$WmiObjCount = $WmiData.Count

if ($WmiObjCount -ne 0) {
$script:WMIInstanceValid = $True
Debug-Out "'$Query' successfully delivered $WmiObjCount objects" $DBG_DESC
} else {
$script:WMIInstanceValid = $False
Debug-Out "'$Query' was successful but did not deliver any data. Reset WmiData object." $DBG_DESC
$WmiData = $Null
}
} catch [Exception] {
Debug-Out "Exception when requesting '$Query' from '$Namespace'." $DBG_DESC
Debug-Out "ErrorMessage: $($_.Exception.Message)" $DBG_DESC
}

return $WmiData
}

#----------------------------------------------------------------

# get ServerView Overall State
function Get-SVOverallState
{
$SVSStateOK = $True
if ($script:CIMProvider -eq $True) {
$CimData = Get-CimQuery -Query "SELECT * FROM SVS_PGYHealthStateComponent WHERE ElementName = 'System'" -Namespace "root/svs"
if ($script:WMIInstanceValid -eq $True) {
Debug-Out "\root/svs:SVS_PGYHealthStateComponent.Presence: $($CimData.Presence)" $DBG_DESC
# Anything but 1 (Present) here indicates a problem with CIM Providers (caused by test automation most likely). Abort.
if ($CimData.Presence -ne 1) {
$SVSStateOK = $False
}
}
} else {
# Anything but 1 (OK) or 2 (Warning) or 3 (Error) here indicates a problem with CIM Providers (caused by test automation most likely). Abort.
$SVSState = Get-ScciData 0x2333 0 0 -1
if ($SVSState -ne 1 -and $SVSState -ne 2 -and $SVSState -ne 3) {
$SVSStateOK = $False
}
}

return $SVSStateOK
}

#----------------------------------------------------------------

function Get-ScciData
{
param (
[int]$opCode,
[int]$opCodeExt,
[int]$objIndex,
[int]$cabID
)

$scciValue = $Null

if ($script:SVAgentRunning -eq $True) {
$Status = $script:oSwitch.ScciQuery($opCode, $opCodeExt, $objIndex, $cabID, 0, [REF]$scciValue, 0)
if ($Status -ne 0) {
Debug-Out "GetScciData: No Data for opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID" $DBG_DESC
$scciValue = $Null
} else {
if ($scciValue -is [system.array]) {
Debug-Out "GetScciData: opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID -&gt; scciValue = '[$scciValue]'" $DBG_DESC
} else {
Debug-Out "GetScciData: opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID -&gt; scciValue = '$scciValue'" $DBG_DESC
}
}
} else {
$scciValue = $Null
}

return $scciValue
}

#----------------------------------------------------------------

function Get-ScciProperty
{
param (
[int]$opCode,
[int]$opCodeExt,
[int]$objIndex,
[int]$cabID,
[string]$strProperty
)

$scciValue = $Null

if ($script:SVAgentRunning -eq $True) {
$Status = $script:oSwitch.ScciQuery($opCode, $opCodeExt, $objIndex, $cabID, $strProperty, [REF]$scciValue, $strProperty.Length+1)
if ($Status -ne 0) {
Debug-Out "GetScciProperty: No Data for opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID '$strProperty' $($strProperty.Length+1)" $DBG_DESC
$scciValue = $Null
} else {
if ($scciValue -is [system.array]) {
Debug-Out "GetScciProperty: opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID '$strProperty' $($strProperty.Length+1) -&gt; scciValue = '[$scciValue]'" $DBG_DESC
} else {
Debug-Out "GetScciProperty: opCode=0x$('{0:X4}' -f $opCode) opCodeExt=0x$('{0:X}' -f $opCodeExt) objIndex=$objIndex cabID=$cabID '$strProperty' $($strProperty.Length+1) -&gt; scciValue = '$scciValue'" $DBG_DESC
}
}
} else {
$scciValue = $Null
}

return $scciValue
}

#----------------------------------------------------------------

# main functionality from here:
# https://blogs.msdn.microsoft.com/dsadsi/2009/02/12/working-with-the-microsoft_ipmi-driver-class-to-retrieve-driver-specific-information-part-1/
# and: https://technet.microsoft.com/pt-br/library/aa392344.aspx
function Invoke-IpmiRequest
{
param (
$NetFunc,
$Lun,
$Cmd
)

Debug-Out "Invoke-IpmiRequest ($NetFunc, $Lun, $Cmd)" $DBG_INFO

# For Microsoft IPMI driver via Get-CIMInstance we need PS V5 and later
if ($PSVersion.Major -ge 5) {
Debug-Out "Get-CimInstance -Namespace 'root\wmi' -Class 'Microsoft_IPMI' " $DBG_DESC
$oIPMI = Get-CimInstance -NameSpace "root\wmi" -Class "Microsoft_IPMI" -ErrorAction Stop
} else {
Debug-Out "Get-WMIObject -Namespace 'root\wmi' -Class 'Microsoft_IPMI' " $DBG_DESC
$oIPMI = Get-WmiObject -NameSpace "root\wmi" -Class "Microsoft_IPMI" -ErrorAction Stop
}

try {
$Response = $oIPMI.RequestResponse($NetFunc, $Lun, $oIPMI.BMCAddress, $Cmd, 0)

Debug-Out "Completion Code = $($Response.CompletionCode)" $DBG_DESC

Debug-Out "Number of ResponseData: $($Response.ResponseDataSize)" $DBG_DESC
for ($i=0; $i -lt $Response.ResponseDataSize; $i++) {
Debug-Out "ResponseData($i): 0x$('{0:X}' -f $Response.ResponseData[$i])" $DBG_DESC
}
} catch [Exception] {
Debug-Out "Exception when Response from IPMI provider." $DBG_DESC
Debug-Out "ErrorMessage: $($_.Exception.Message)" $DBG_DESC
$Response = $Null
}

return $Response
}

#................................................................

#-------------------------------------------------------------------
# Logging.ps1
#-------------------------------------------------------------------

$script:MPVERSION = "8.5.0.0"

#DebugLevel options are defined in bits and may be combined using binary Or
Set-Variable -Name DBG_NO -Option Constant -Value 0 # 0000: print no debug lines
Set-Variable -Name DBG_INFO -Option Constant -Value 1 # 0001: print informational debug lines
Set-Variable -Name DBG_DATA -Option Constant -Value 2 # 0010: print SCCI/CIM data related debug lines
Set-Variable -Name DBG_DESC -Option Constant -Value 4 # 0100: print lines relevant for documentation document
Set-Variable -Name DBG_SCOM -Option Constant -Value 8 # 1000: print SCOM related information
Set-Variable -Name DBG_ALL -Option Constant -Value 3 # 0011: standard output

$script:DebugMode = $False
$script:DebugFile = $False
$script:DebugLevel = ""
$script:DebugTest = ""
$script:DebugOverWrite = $True
if (-not [string]::IsNullOrEmpty($DbgLevel) -and ($DbgLevel -match '^\d+$')) { $script:DebugLevel = [convert]::ToInt32($DbgLevel, 10) }
if (-not [string]::IsNullOrEmpty($DbgTest)) { $script:DebugTest = "$DbgTest".ToUpper() }

Set-Variable -Name SVISCOMLogBase -Option Constant -Value "SVISCOM"
Set-Variable -Name SVISCOMLogPath -Option Constant -Value "SVISCOM-Win"
Set-Variable -Name SVISCOMLogIniName -Option Constant -Value "SVISCOMLog.ini"
Set-Variable -Name SVISCOMLogIn_Name -Option Constant -Value "SVISCOMLog.in_"
$script:LogFileDirBase = ""
$script:LogFileDir = ""
$script:SVISCOMLogIni = ""
$script:SVISCOMLogIn_ = ""
$script:LogFilePath = ""
$script:lineCounter = 0

Set-Variable -Name SEC_ServerDiscovery -Option Constant -Value "[ServerDiscovery]"
Set-Variable -Name SEC_ComponentsMonitor -Option Constant -Value "[ComponentsMonitor]"
Set-Variable -Name SEC_PerfMonMonitor -Option Constant -Value "[PerfMonMonitor]"
Set-Variable -Name SEC_FCEvents -Option Constant -Value "[FCEvents]"
Set-Variable -Name SEC_ResetPYServerData -Option Constant -Value "[ResetPYServerData]"
Set-Variable -Name STR_DBGMODE -Option Constant -Value "DebugMode"
Set-Variable -Name STR_OVERWRITE -Option Constant -Value "OverWrite"
Set-Variable -Name STR_DBGLEVEL -Option Constant -Value "DebugLevel"
Set-Variable -Name STR_DBGTEST -Option Constant -Value "DebugTest"

#-------------------------------------------------------------------

function Initialize-Logging
{
param (
$SectionIni,
$Component
)

# get the system environment variable TEMP (usually: C:\Windows\TEMP), depending on e.g. partition
$TEMP = $Env:TEMP
$SYSTEMDRIVE = $Env:SYSTEMDRIVE

$script:LogFileDirBase = "$TEMP\$SVISCOMLogBase"
$script:LogFileDir = "$TEMP\$SVISCOMLogBase\$SVISCOMLogPath"
$script:SVISCOMLogIni = "$LogFileDir\$SVISCOMLogIniName"
$script:SVISCOMLogIn_ = "$LogFileDir\$SVISCOMLogIn_Name"
if ($script:MGMGroup -ne "") {
if ($Component -ne "") {
$script:LogFileFullName = "$($LogFileName)_$($script:TargetComputer)_$($script:MGMGroup)_$($Component).log"
} else {
$script:LogFileFullName = "$($LogFileName)_$($script:TargetComputer)_$($script:MGMGroup).log"
}
} else {
if ($Component -ne "") {
$script:LogFileFullName = "$($LogFileName)_$($script:TargetComputer)_$($Component).log"
} else {
$script:LogFileFullName = "$($LogFileName)_$($script:TargetComputer).log"
}
}
$script:LogFilePath = "$LogFileDir\$($script:LogFileFullName)"

# get setting for DebugMode and DebugFile
if ($script:DebugMode -eq $False) {
Get-LogFileIni $SVISCOMLogIni $SectionIni
# Default DebugLevel: All
if ("$($script:DebugLevel)" -eq "" -and $script:DebugMode -eq $True) { $script:DebugLevel = $DBG_ALL }
}
if ($script:DebugMode -eq $True) { $script:DebugFile = $True }

Debug-Out "TEMP = $TEMP" $DBG_INFO
Debug-Out "SYSTEMDRIVE = $SYSTEMDRIVE" $DBG_INFO
Debug-Out "LogFileDirBase = $($script:LogFileDirBase)" $DBG_INFO
Debug-Out "LogFileDir = $($script:LogFileDir)" $DBG_INFO
Debug-Out "SVISCOMLogIni = $($script:SVISCOMLogIni)" $DBG_INFO
Debug-Out "SVISCOMLogIn_ = $($script:SVISCOMLogIn_)" $DBG_INFO
Debug-Out "TargetComputer = $($script:TargetComputer)" $DBG_INFO
Debug-Out "LogFileName = $LogFileName" $DBG_INFO
Debug-Out "LogFilePath = $($script:LogFilePath)" $DBG_INFO
Debug-Out "DebugMode = $($script:DebugMode)" $DBG_INFO
Debug-Out "OverWrite = $($script:DebugOverWrite)" $DBG_INFO
Debug-Out "DebugLevel = $($script:DebugLevel)" $DBG_INFO
Debug-Out "DebugTest = $($script:DebugTest)" $DBG_INFO

# check whether this is a new MP and do all new MP stuff here
$OldMPVersion = Get-PYServerData "MPVersion"
if ($MPVersion -ne $OldMPVersion) {
if ($OldMPVersion -ne "") { Debug-Out "Old MPVersion V$OldMPVersion" $DBG_INFO }
Debug-Out "New MPVersion V$($script:MPVersion)" $DBG_INFO

$regPath32_FSC = "SOFTWARE\Fujitsu Siemens\ServerView SCOM Integration\PYServerData"
$regPath32_SCOMINTEG = "SOFTWARE\Fujitsu Siemens\ServerView SCOM Integration"
$regPath64_FSC = "SOFTWARE\Wow6432Node\Fujitsu Siemens\ServerView SCOM Integration\PYServerData"
$regPath64_SCOMINTEG = "SOFTWARE\Wow6432Node\Fujitsu Siemens\ServerView SCOM Integration"
$regPath32_V7 = "SOFTWARE\Fujitsu\ServerView Suite\SCOM Integration\PYServerData"
$regPath64_V7 = "SOFTWARE\Wow6432Node\Fujitsu\ServerView Suite\SCOM Integration\PYServerData"

# Remove any old Registry paths and values
if (Test-Path -Path "HKLM:\$regPath32_FSC") { Remove-Item -Path "HKLM:\$regPath32_FSC" -Recurse }
if (Test-Path -Path "HKLM:\$regPath32_SCOMINTEG") { Remove-Item -Path "HKLM:\$regPath32_SCOMINTEG" -Recurse }
if (Test-Path -Path "HKLM:\$regPath64_FSC") { Remove-Item -Path "HKLM:\$regPath64_FSC" -Recurse }
if (Test-Path -Path "HKLM:\$regPath64_SCOMINTEG") { Remove-Item -Path "HKLM:\$regPath64_SCOMINTEG" -Recurse }
if (Test-Path -Path "HKLM:\$regPath32_V7") { Remove-Item -Path "HKLM:\$regPath32_V7" -Recurse }
if (Test-Path -Path "HKLM:\$regPath64_V7") { Remove-Item -Path "HKLM:\$regPath64_V7" -Recurse }

# clear PY server data
Debug-Out "Remove PYServerData for V$($script:MPVersion)" $DBG_INFO
Clear-AllPYServerData

# Save new MP Version
Save-PYServerData "MPVersion" $MPVersion
}

if ($script:DebugFile -eq $True) {
Initialize-LogFile
}
}

#----------------------------------------------------------------

function Initialize-LogFile
{
$startTime = Get-Date -format "yyyy-MM-dd HH:mm:ss"
$script:lineCounter = 0

$sMessage = "`r`n********** $startTime **********`r`n********** $($script:LogFilePath) **********"
$sMPVersion = "MP Version: *** $($MPVersion) ***`r`n"

if (Test-Path -Path $script:LogFilePath) {
Debug-Out "Log file exists at: $($script:LogFilePath)" $DBG_INFO
if ($script:DebugOverWrite -eq $True) {
Remove-Item -Path $script:LogFilePath -Force | Out-Null
}
}

if (-not (Test-Path -Path $script:LogFilePath)) {
New-Item -Path $script:LogFilePath -ItemType File | Out-Null
}

try {
if (Test-Path -Path $script:LogFileDir -ErrorAction Stop) {
Debug-Out "Log file folder exists at: $($script:LogFileDir)" $DBG_INFO
# move all log files from old log folder to new log folder
$LogFiles = Get-Childitem -Path $script:LogFileDirBase\*.log -ErrorAction Stop
if ($Null -ne $LogFiles) {
Debug-Out "Move all files from old log folder ($($script:LogFileDirBase)) to new log folder" $DBG_INFO
$LogFiles | Move-Item -Destination $script:LogFileDir -Force
}
} else {
Debug-Out "Create log file folder at: $($script:LogFileDir)" $DBG_INFO
$Null = New-Item -Path $script:LogFileDir -ItemType Directory -ErrorAction Stop
}
} catch {
Debug-Out "Could not access log file folder: $($script:LogFileDir). Abort Logging." $DBG_INFO
$script:DebugMode = $False
$script:DebugFile = $False
}

Add-Content -Path $script:LogFilePath -Value $sMessage
Add-Content -Path $script:LogFilePath -Value $sMPVersion
}


#----------------------------------------------------------------

function Get-LogFileIni
{
param (
[string] $FilePathName,
[string] $Section
)

if (Test-Path -Path $FilePathName) {
Debug-Out "Get INI file values from '$FilePathName', section '$Section'" $DBG_INFO
$thisVal = $(Get-IniValue $FilePathName $Section $STR_DBGMODE).ToUpper()
if (($thisVal -ne "") -and
($thisVal -eq "YES" -or $thisVal -eq "TRUE" -or $thisVal -eq "1")) {
$script:DebugMode = $True
$script:DebugFile = $True
}

$thisVal = $(Get-IniValue $FilePathName $Section $STR_OVERWRITE).ToUpper()
if (($thisVal -ne "") -and
($thisVal -eq "NO" -or $thisVal -eq "FALSE" -or $thisVal -eq "0")) {
$script:DebugOverWrite = $False
}

$thisVal = $(Get-IniValue $FilePathName $Section $STR_DBGLEVEL).ToUpper()
#if (($script:DebugLevel -eq "" -or $script:DebugLevel -eq 0) -and
# ($thisVal -ne "" -and $thisVal -match '^\d+$')) {
if ($script:DebugLevel -eq "" -and $thisVal -ne "") {
$script:DebugLevel = $thisVal
} else {
#Debug-Out "DebugLevel '$thisVal' is NO number. Ignore." $DBG_INFO
}

$thisVal = $(Get-IniValue $FilePathName $Section $STR_DBGTEST).ToUpper()
if ($script:DebugTest -eq "" -and $thisVal -ne "") {
$script:DebugTest = $thisVal
}
} else {
Debug-Out "INI file '$FilePathName' does not exist." $DBG_INFO
}
}

#----------------------------------------------------------------

function Get-IniValue
{
param (
[string] $FilePathName,
[string] $Section,
[string] $KeyValue
)

$regex = [RegEx]"$KeyValue=(?&lt;Value&gt;.+$)"

# Get file content
$inLines = Get-Content $FilePathName
for ($i = 0; $i -lt $inLines.Length; $i++) {
# ignore comment lines
if (!"$($inLines[$i])".StartsWith(";")) {
# Find section
if ($inLines[$i] -contains "$Section") {
do {
$Res = $regex.Match($inLines[$i])
if ($Res.Success) {
if (!"$($inLines[$i])".StartsWith(";")) {
return $($Res.Groups['Value'].Value)
} else {
return ""
}
break
}
$i++
} until ($i -ge $inLines.Length -or "$($inLines[$i])".Contains("["))
}
}
}

return ""
}

#----------------------------------------------------------------

function Debug-Out
{
param (
[string] $Text,
[int] $Level
)

if ($Level -bAnd $script:DebugLevel) {
if ($script:DebugMode -eq $True) {
Write-Host $Text

if ($script:DebugFile -eq $True) {
if (($script:LogFilePath -ne "") -and (Test-Path -Path $script:LogFilePath)) {
$script:lineCounter++
Add-Content -Path $script:LogFilePath -Value "[$($script:lineCounter)] $(Get-Date -Format "yyyy-MM-dd HH:mm:ss") $Text"
}
}
}
}
}

#................................................................
#-------------------------------------------------------------------
# Utils.ps1
#-------------------------------------------------------------------

$script:SVISCOMName = "SVISCOM-Win"

#-------------------------------------------------------------------

Set-Variable -Name regRootSVUUIDPath -Option Constant -Value "SYSTEM\CurrentControlSet\Control\UUID\C3681B60-0D26-11D3-8319-00A0C9B61E25"
Set-Variable -Name regRootSVAgentsPathname -Option Constant -Value "ServerView Snmp Agents"
Set-Variable -Name regRootSVRAIDPathname -Option Constant -Value "ServerView RAID"
Set-Variable -Name SVAgentName -Option Constant -Value "ServerView Agents"
Set-Variable -Name SVAgentOverallState -Option Constant -Value "ServerView Health State"
Set-Variable -Name SVAgentVersionString -Option Constant -Value "$SVAgentName Version"
Set-Variable -Name SVRaidName -Option Constant -Value "ServerView RAID"
Set-Variable -Name SVRaidOverallState -Option Constant -Value "$SVRaidName OverallState"
Set-Variable -Name SVRaidVersionString -Option Constant -Value "$SVRaidName Version"
Set-Variable -Name SVCommunicationMonitor -Option Constant -Value "Communication Monitor"
Set-Variable -Name SVCommunication -Option Constant -Value "CommunicationMonitor"
Set-Variable -Name SVISCOMWinPath -Option Constant -Value "SOFTWARE\Fujitsu\ServerView Suite\SCOM Integration\SVISCOM-Win"
Set-Variable -Name SVISCOMPYPath -Option Constant -Value "$SVISCOMWinPath\PYServerData"
$script:SVAgentsPathname = "Pathname"
$script:CIMProvider = $False
$script:SVAgentRunning = $False
$script:SVASRunning = $False
$script:isNano = $False

$script:Cabinet = 0
$script:CabinetArray = @(-1,$Null,$Null,$Null,$Null,$Null)

#-------------------------------------------------------------------

function Get-OSProperty
{
param (
$property
)

$osProperty = ""
try {
$osProperty = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" -ErrorAction Stop).$Property
} catch {
$osProperty = ""
}
# Debug-Out "OS property $property: $osProperty" $DBG_INFO

return $osProperty
}

#----------------------------------------------------------------

function Get-SVAgentsPath
{
$AgentsPath = ""
try {
$regSVAgentsPath = (Get-ItemProperty "HKLM:\$regRootSVUUIDPath" -ErrorAction Stop).$regRootSVAgentsPathname
$regSVAgentsPath = "$regSVAgentsPath\STATUS_MIB\CurrentVersion"
$AgentsPath = (Get-ItemProperty "HKLM:\$regSVAgentsPath" -ErrorAction Stop).$SVAgentsPathname
} catch {
$AgentsPath = ""
}
# Debug-Out "SV-Agents Path: $AgentsPath" $DBG_INFO

return $AgentsPath
}

#----------------------------------------------------------------

function Get-SVAgentsRunning
{
$AgentsRunning = $False
try {
if ((Get-Service -Name SrvCtrl -ErrorAction Stop).Status -eq "Running") {
$AgentsRunning = $True
}
} catch {
$AgentsRunning = $False
}
# Debug-Out "ServerView Agent Service found running = $AgentsRunning)", DBG_INFO

return $AgentsRunning
}

#----------------------------------------------------------------

function Get-SVRaidVersion
{
$RaidVersion = ""
try {
$regSVRAIDPath = (Get-ItemProperty "HKLM:\$regRootSVUUIDPath" -ErrorAction Stop).$regRootSVRAIDPathname
$RaidVersion = (Get-ItemProperty "HKLM:\$regSVRAIDPath" -ErrorAction Stop).Version
if ($Null -eq $RaidVersion) { $RaidVersion = "" }
} catch {
# Debug-Out "Error while determining ServerView RAID Version." $DBG_INFO
$RaidVersion = ""
}

if ($RaidVersion -eq "" ) {
# there still might be a really old Version installed ...
$RaidRegistryList = @( "SOFTWARE\Fujitsu Siemens Computers\ServerView RAID",
"SOFTWARE\Fujitsu\ServerView RAID",
"SOFTWARE\Wow6432Node\Fujitsu Siemens Computers\ServerView RAID",
"SOFTWARE\Wow6432Node\Fujitsu\ServerView RAID")

foreach ($path in $RaidRegistryList) {
if ($RaidVersion -eq "") {
try {
$RaidVersion = (Get-ItemProperty "HKLM:\$path" -ErrorAction Stop).Version
if ($Null -eq $RaidVersion) { $RaidVersion = "" }
} catch {
$RaidVersion = ""
}
} else {
# Debug-Out "Skip HKLM:\$path" $DBG_INFO
}
}
}

if ($RaidVersion -ne "" ) {
Debug-Out "ServerView RAID Version: $RaidVersion" $DBG_INFO
} else {
Debug-Out "ServerView RAID NOT installed" $DBG_INFO
}

return $RaidVersion
}

#----------------------------------------------------------------

function Get-PYServerData
{
param (
[string]$strValueName
)

$strValue = ""
try {
#Debug-Out "GetPYServerData: Read '$strValueName' from 'HKLM:\$SVISCOMPYPath'." $DBG_DATA
$strValue = (Get-ItemProperty "HKLM:\$SVISCOMPYPath" -ErrorAction Stop).$strValueName
if ($Null -eq $strValue) {
$strValue = ""
} else {
Debug-Out "GetPYServerData: $($strValueName): '$strValue'" $DBG_DATA
}
} catch {
Debug-Out "GetPYServerData: Error on reading $strValueName" $DBG_DATA
}

return $strValue
}

#----------------------------------------------------------------

function Save-PYServerData
{
param (
[string]$strValueName,
[string]$strValue
)

try {
if (! (Test-Path -Path "HKLM:\$SVISCOMPYPath")) {
Debug-Out "SavePYServerData: Registry Path 'HKLM:\$SVISCOMPYPath' does not exist. Create." $DBG_DATA
New-Item -Path HKLM:\$SVISCOMWinPath -Name "PYServerData" -Force -ErrorAction Stop
} else {
#Debug-Out "SavePYServerData: Registry Path 'HKLM:\$SVISCOMPYPath' already exists." $DBG_DATA
}
Debug-Out "$($strValueName): '$strValue' saved" $DBG_INFO
$Null = Set-ItemProperty -Path "HKLM:\$SVISCOMPYPath" -Name $strValueName -Value $strValue -Type String -ErrorAction Stop
} catch {
Debug-Out "SavePYServerData: Error on writing $strValueName" $DBG_DATA
}
}

#----------------------------------------------------------------

function Clear-PYServerData
{
param (
[string]$strValueName
)

try {
if (! (Test-Path -Path "HKLM:\$SVISCOMPYPath")) {
Debug-Out "DeletePYServerData: Registry Path 'HKLM:\$SVISCOMPYPath' does not exist." $DBG_DATA
} else {
$strValue = (Get-ItemProperty "HKLM:\$SVISCOMPYPath" -ErrorAction Stop).$strValueName
if ([string]::IsNullOrEmpty($strValue)) {
Debug-Out "DeletePYServerData: Registry value '$strValueName' does not exist." $DBG_DATA
} else {
Debug-Out "DeletePYServerData: Delete '$strValueName' from PYServerData" $DBG_DATA
$Null = Remove-ItemProperty -Path "HKLM:\$SVISCOMPYPath" -Name $strValueName -ErrorAction Stop
}
}
} catch {
Debug-Out "DeletePYServerData: Error on deleting $strValueName" $DBG_DATA
}
}

#----------------------------------------------------------------

function Clear-AllPYServerData
{
Clear-PYServerData "AgentVersion"
Clear-PYServerData "OSVersion"
Clear-PYServerData "MPVersion"
foreach ($Component in $script:ComponentsStateList) {
Clear-PYServerData $Component
Clear-PYServerData "$($Component)Valid"
}
# make sure old/unused registry values are cleared
Clear-PYServerData "PowerConsumptionMonitor"
Clear-PYServerData "RaidPhysicalDisk"
Clear-PYServerData "RaidLogicalDrive"
}

#----------------------------------------------------------------

function ConvertTo-MatchingUnit
{
param (
$orgValue
)

$newUnitLimit = 1023

if ($orgValue -eq 0) {
$TotalLocalUnit = 0
$SizeUnit = " Bytes"
} else { # Start with Megabytes
$SizeUnit = "MB"
$TotalLocalUnit = [math]::round($orgValue / 1MB, 2)
if ($TotalLocalUnit -gt $newUnitLimit) { # Gigabytes
$SizeUnit = "GB"
$TotalLocalUnit = [math]::round($orgValue / 1GB, 2)
if ($TotalLocalUnit -gt $newUnitLimit) { # Terabytes
$SizeUnit = "TB"
#$TotalLocalUnit = [math]::round($orgValue / 1TB, 2)
$TotalLocalUnit = [math]::round($orgValue / (1KB*1GB), 2)
if ($TotalLocalUnit -gt $newUnitLimit) { # Petabytes
$SizeUnit = "PB"
#$TotalLocalUnit = [math]::round($orgValue / 1PB, 2)
$TotalLocalUnit = [math]::round($orgValue / (1MB*1GB), 2)
if ($TotalLocalUnit -gt $newUnitLimit) { # Exabytes
$SizeUnit = "EB"
#$TotalLocalUnit = [math]::round(($orgValue / 1PB) / 1KB, 2)
$TotalLocalUnit = [math]::round(($orgValue / (1MB*1GB)) / 1KB, 2)
}
}
}
}
}

Debug-Out "Converted $orgValue to '$TotalLocalUnit $SizeUnit'" $DBG_INFO

return "$TotalLocalUnit $SizeUnit"
}

#----------------------------------------------------------------

function Get-iRMCDNSName
{
$BMCHttpsEnabled = Get-ScciData 0xE001 0x1425 0x0 $script:Cabinet
Debug-Out "BMC Https Enabled: $BMCHttpsEnabled" $DBG_DATA

if ($Null -ne $BMCHttpsEnabled -and $BMCHttpsEnabled -ne 0) {
$BMCHttpsPort = Get-ScciData 0xE001 0x1421 0x0 $script:Cabinet
Debug-Out "BMC Https Port: $BMCHttpsPort" $DBG_DATA
} else {
$BMCHttpPort = Get-ScciData 0xE001 0x1420 0x0 $script:Cabinet
Debug-Out "BMC Http Port: $BMCHttpPort" $DBG_DATA
}

$BMCError = 0
$BMCUseBmcName = Get-ScciData 0xE001 0x1431 0x0 $script:Cabinet
if ($Null -eq $BMCUseBmcName) {
$BMCError ++
$BMCUseBmcName = 0 #set to a defined / usable value
}
Debug-Out "Use Bmc Name: $BMCUseBmcName" $DBG_DATA

$BMCAddSerial = Get-ScciData 0xE001 0x1433 0x0 $script:Cabinet
if ($Null -eq $BMCAddSerial) {
$BMCError ++
$BMCAddSerial = 0 #set to a defined / usable value
}
Debug-Out "Add Serial: $BMCAddSerial" $DBG_DATA

if ($BMCAddSerial -eq 1) {
$BMCMACAddrArr = Get-ScciData 0xE001 0x1445 0x0 $script:Cabinet
if ($BMCMACAddrArr -is [system.array]) {
$i = 0
foreach ($byte in $BMCMACAddrArr)
{
$byteinhex = [String]::Format("{0:X}", $byte) # Convert byte to hex.
if ($i -ge 3) {
$BMCBoardSerial += $byteinhex.PadLeft(2,"0") # Pad with two zeros.
}
$BMCMACAddr += $byteinhex.PadLeft(2,"0") # Pad with two zeros.
$BMCMACAddr += ":"
$i++
}
$BMCMACAddr = $BMCMACAddr.Substring(0,$BMCMACAddr.Length-1)
Debug-Out "MAC address = $BMCMACAddr" $DBG_DATA
Debug-Out "MAC 'serial' = $BMCBoardSerial" $DBG_DATA
} else {
$BMCAddSerial = 0
}
}

$BMCAddExt = Get-ScciData 0xE001 0x1434 0x0 $script:Cabinet
if ($Null -eq $BMCAddExt) {
$BMCError ++
$BMCAddExt = 0 #set to a defined / usable value
}
Debug-Out "Add Ext = $BMCAddExt" $DBG_DATA

if ($BMCAddExt -eq 1) {
$BMCNameExt = Get-ScciData 0xE001 0x1432 0 $script:Cabinet
if ($Null -eq $BMCNameExt) {
$BMCError ++
$BMCAddExt = 0
}
Debug-Out "BMC Name Ext = $BMCNameExt" $DBG_DATA
}

if ($BMCUseBmcName -eq 1) {
$BMCBmcName = Get-ScciData 0xE001 0x1430 0 $script:Cabinet
} else {
# misuse same variable holding the result ...
$BMCBmcName = Get-ScciData 0xE001 0x0201 0 $script:Cabinet
}
if ($Null -eq $BMCBmcName) {
$BMCError ++
$BMCBmcName = ""
}
Debug-Out "BMC network name = $BMCBmcName" $DBG_DATA

if ($BMCError -gt 1) {
$iRMCDNSName = "N/A"
} else {
# Strip whitespaces from Hostname
$BMCBmcName = $BMCBmcName.Trim()
$BMCBmcName = $BMCBmcName -Replace '\s',''

#Find "." in Hostname and terminate
if ($BMCBmcName.Contains(".")) { $BMCBmcName = ($BMCBmcName -Split ".")[0] }
#Debug-Out "BMC name = '$BMCBmcName'" $DBG_DATA

if ($BMCAddSerial -eq 1) {
$iRMCDNSName = $BMCBmcName + $BMCBoardSerial.Trim()
} else {
$iRMCDNSName = $BMCBmcName
}
#Debug-Out "BMC name = '$BMCBmcName'" $DBG_DATA
if ($BMCAddExt -eq 1) {
$iRMCDNSName = $iRMCDNSName + $BMCNameExt.Trim()
}
Debug-Out "BMC name = '$BMCBmcName'" $DBG_DATA

# Again: Strip whitespaces from Hostname
$iRMCDNSName = $iRMCDNSName.Trim()
$iRMCDNSName = $iRMCDNSName -Replace '\s',''
Debug-Out "BMC DNS name = '$iRMCDNSName'" $DBG_DATA

$BMCDNSDomain = Get-ScciData 0xE001 0x144D 0 $script:Cabinet
if ($Null -eq $BMCDNSDomain) {
Debug-Out "BMC domain name not set!" $DBG_DATA
$BMCDNSDomain = ""
} else {
$iRMCDNSName = "$iRMCDNSName.$BMCDNSDomain"
Debug-Out "BMC DNS name = '$iRMCDNSName'" $DBG_DATA
}

if ($BMCHttpsEnabled -eq 0) {
if ($BMCHttpPort -ne "" -and $Null -ne $BMCHttpPort) {
$iRMCDNSName = "http://$($iRMCDNSName):$BMCHttpPort"
} else {
$iRMCDNSName = "http://$iRMCDNSName"
}
} else {
if ($BMCHttpsPort -ne "" -and $Null -ne $BMCHttpsPort) {
$iRMCDNSName = "https://$($iRMCDNSName):$BMCHttpsPort"
} else {
$iRMCDNSName = "https://$iRMCDNSName"
}
}
}

return $iRMCDNSName
}

#................................................................


#-------------------------------------------------------------------
# Main.ps1
#-------------------------------------------------------------------
Main $args
</Script></ScriptBody>
<Parameters>
<Parameter>
<Name>SourceId</Name>
<Value>$MPElement$</Value>
</Parameter>
<Parameter>
<Name>ManagedEntityId</Name>
<Value>$Target/Id$</Value>
</Parameter>
<Parameter>
<Name>PrincipalName</Name>
<Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
</Parameter>
<Parameter>
<Name>TargetComputer</Name>
<Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</Value>
</Parameter>
<Parameter>
<Name>ManagementGroup</Name>
<Value>$Target/ManagementGroup/Name$</Value>
</Parameter>
</Parameters>
<TimeoutSeconds>300</TimeoutSeconds>
<StrictErrorHandling>false</StrictErrorHandling>
</DataSource>
</Discovery>