0

下面是我清除了标识符的脚本。诊断的基类是 MyCompany.MyApp,其基类是 Windows 计算机。如果我直接在目标机器上使用参数运行它,我将返回 XML。如果我从我的电脑运行它是空白的。这在本地是有道理的,但是我认为当您运行发现时,代理会在您的目标机器上运行它?到目前为止,我所有的其他发现都是注册表,所以我可能做错了什么。

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)
}
4

1 回答 1

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

于 2016-10-06T22:22:41.627 回答