0

Below is my script with identifiers scrubbed. The Base Class for Diagnostics is MyCompany.MyApp and the base class of that is Windows Computer. If I run this on the target machine directly with parameters I am getting XML returned. If I run from my PC it is blank. That makes sense locally, but I thought when you run discoveries that the agent runs it on the machine you are targeting? All my other discoveries thus far have been registry so it is possible I am doing something completely wrong.

Param($sourceId, $managedEntityId, $ComputerName)

$api = New-Object -ComObject 'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)

$Diagnostics = Invoke-Command -ComputerName $ComputerName {
    Get-WebApplication -Name "diagnostics"
}

foreach ($x in $Diagnostics)
{
    $instance = $discoveryData.CreateClassInstance("$MPElement[Name='MyCompany.MyApp.Diagnostics']$")
    $instance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", $ComputerName)
    $discoveryData.AddInstance($instance)
}
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Kenny
  • 74
  • 7

1 Answers1

0

As the first, most obvious reason, you don't output the discovery data onto output stream (StdOut). Just simple add $discoveryData at a new line by the end of your script.

Moreover, more information about your class and MP architecture required. I'd probably recommend you to use Windows!Microsoft.Windows.ComputerRole as base class and host it on target computer object.

Regards Max

Max
  • 751
  • 6
  • 10