The following procedures show how to create a PowerShell script discovery using the Operations Manager 2007 Authoring console and Visual Studio Authoring Extensions. This exercise is part of the System Center Operations Manager Management Pack Authoring Center.
This exercise applies to the following products:
Before you perform this procedure, you must first complete the following prerequisite procedures:
The Microsoft System Center team has validated this procedure as of the original version. We will continue to review any changes and periodically provide validations on later revisions as they are made. Please feel free to make any corrections or additions to this procedure that you think would assist other users
Sample code is available in the TechNet Gallery for this exercise so that you can validate your results.
This procedure implements the same discovery as in the procedure How to Create a Script Discovery (VBScript) by using Windows PowerShell instead of VBScript. Both can be in the same management pack, but one should be disabled so that they don't attempt to discover the same instances. The discovery created in this procedure has the following characteristics:
The Operations Manager Authoring console does not include a wizard for creating this kind of discovery. Therefore, a custom discovery must be created.
param($sourceId,$managedEntityId,$computerName)
$api = new-object -comObject
'MOM.ScriptAPI'
$discoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)
for ($i=1; $i -le 3; $i++)
{
$instance = $discoveryData.CreateClassInstance(
"$MPElement[Name='MyMP.MyApplicationComponent']$"
)
$instance.AddProperty(
"$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$"
, $computerName)
"$MPElement[Name='MyMP.MyApplicationComponent']/ComponentName$"
, 'Component' + $i)
$discoveryData.AddInstance($instance)
}
$discoveryData
<
Parameters
>
Parameter
Name
>sourceID</
Value
>$MPElement$</
</
>managedEntityID</
>$Target/Id$</
>computerName</
>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</
<!-- IntervalSeconds specifies how often we will run the discovery. -->
IntervalSeconds
>14400</
<!-- SyncTime specifies the minutes after the hour to synchronize execution of the discovery. -->
SyncTime
/>
<!-- ScriptName specifies the name of the script. -->
ScriptName
>DiscoverMyApplicationComponent.ps1</
<!-- ScriptBody is the text of the script. In this case, a variable is used to specify the script file in the VSAE project -->
ScriptBody
>$IncludeFileContent/DiscoverApplicationComponents.ps1$</
<!-- Parameters for the script. -->
<!-- TimeoutSeconds is the seconds that the script must be running before it is automatically ended. -->
TimeoutSeconds
>300</
Richard Mueller edited Revision 3. Comment: Replaced RGB values with color names in HTML to restore colors
Richard Mueller edited Revision 2. Comment: Removed blank headings and fixed duplicate <a name> tags in HTML
Richard Mueller edited Revision 1. Comment: Removed (en-US) from title, added tags