DSRefreshScript (Resource)

Element properties:

TypeResource
File NameDiagnosticServers.ps1
AccessibilityInternal

Source Code:

<Resource ID="DSRefreshScript" FileName="DiagnosticServers.ps1" Accessibility="Internal"/>

File Content: DiagnosticServers.ps1

# Our custom class which is successfully discovered via discovery script

# <ClassType ID="Quest.SoSSE.DiagnosticServers" Base="Windows!Microsoft.Windows.Computer" Accessibility="Public" Abstract="false" Hosted="false" Singleton="false">
# <Property ID="Version" Key="false" Type="string" Required="true"/>
# <Property ID="Status" Key="false" Type="string" Required="false"/>
# </ClassType>

$dsClass = Get-SCOMClass -Name Quest.SoSSE.DiagnosticServers

$dsClassInstances = Get-SCOMClassInstance -Class $dsClass
foreach ($dsClassInstance in $dsClassInstances)
{
try
{
#Tried this – failed with exception: the given key was not present in the dictionary
# $dataObject = $ScriptContext.CreateFromObject($dsClassInstance, "Id=Id,DisplayName=DisplayName,HealthState=HealthState,InMaintenanceMode=InMaintenanceMode, DSVersion='[Quest.SoSSE.DiagnosticServers].Version'", $null)

$dataObject = $ScriptContext.CreateFromObject($dsClassInstance, "Id=Id,DisplayName=DisplayName,HealthState=HealthState,InMaintenanceMode=InMaintenanceMode", $null)
$dataObject["DSVersion"]= $dsClassInstance.'[Quest.SoSSE.DiagnosticServers].Version'.value
$dataObject["Status"]= $dsClassInstance.'[Quest.SoSSE.DiagnosticServers].Status'.value
}
catch
{
$dataObject["Status"]= $_.Exception.Message
# throw "$dataObject Error: " + $_.Exception.Message
}

# throw "`n`nCheck values being returned:`n`n DisplayName - " + [string] $dataObject["DisplayName"] +
"`n DSVersion I get here- " # + [string] $dataObject["DSVersion"]

$ScriptContext.ReturnCollection.Add($dataObject)
}