locked
how can i create a target using powershell script and also for discovery RRS feed

  • Question

  • I am currently SCOM 2012 r2 and MP Author for creating a management pack,

    In MPAuthor how can i add discovery scripts and sample target powershell script to target a specific application.

    param($sourceId,$managedEntityId)
    $service="http://localhost:5460/Service.svc"
    $api= New-Object -ComObject 'MOM.ScriptAPI'
    $discoverydata=$api.CreateDiscoveryData(0,$sourceId,$managementEntityId)
    $proxy = New-WebServiceProxy -Uri http://localhost:5460/Service.svc
    $value=$proxy.GetEmployees();
    foreach($names in $value)
    {
    $instance=$discoverydata.CreateClassInstance("$MPElement[Name='SystemPulseEpic.Service']$")
    $instance.AddProperty("$MPElement[Name='SystemPulseEpic.Service']/Servicesvc$",$names.EmpName)
    $instance.AddProperty("$MPElement[Name='SystemPulseEpic.Service']/GetEmployee$",$names.DeptName)
    $discoverydata.AddInstance($instance)

    }
    $discoverydata

    here is my discovery script.


    Thanks & Regards, Suresh Gaddam

    Tuesday, January 27, 2015 9:43 AM

Answers

  • I found my answer myself,there is problem with the windows computer target,so i used windows server computer and i removed some unwanted stuff from the management pack and now it is working extremely fine..

    Thanks & Regards, Suresh Gaddam

    • Marked as answer by Suresh Gaddam Monday, February 2, 2015 10:59 AM
    Monday, February 2, 2015 10:59 AM

All replies

  • Hi,

    You may refer to the articles below:

    Using System Center Operations Manager and PowerShell to monitor…anything–part 3: Discoveries with PowerShell

    http://hindenes.com/trondsworking/2011/09/06/using-system-center-operations-manager-and-powershell-to-monitoranythingpart-3-discoveries-with-powershell/

    How to Create a Windows PowerShell Discovery

    https://technet.microsoft.com/en-us/library/ee957031.aspx

    Regards,

    Yan Li


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Wednesday, January 28, 2015 5:44 AM
  • I took the script from there itself,could you please look at my script and tell me where is problem.

    and i wrote a management pack for discovery even that is not working.could you please verify the MP

    <ManagementPack ContentReadable="true" SchemaVersion="2.0" OriginalSchemaVersion="2.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <Manifest>
        <Identity>
          <ID>ServiceWCF</ID>
          <Version>1.0.0.19</Version>
        </Identity>
        <Name>ServiceWCF</Name>
        <References>
          <Reference Alias="Windows">
            <ID>Microsoft.Windows.Library</ID>
            <Version>7.5.8501.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
          </Reference>
          <Reference Alias="System">
            <ID>System.Library</ID>
            <Version>7.5.8501.0</Version>
            <PublicKeyToken>31bf3856ad364e35</PublicKeyToken>
          </Reference>
        </References>
      </Manifest>
      <TypeDefinitions>
        <EntityTypes>
          <ClassTypes>
            <ClassType ID="ServiceWCF.Computer.ComputerRole" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.ComputerRole" Hosted="true" Singleton="false" Extension="false">
              <Property ID="ServiceName" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" Scale="0" />
            </ClassType>
            <ClassType ID="ServiceWCF.Computer.Service" Accessibility="Internal" Abstract="false" Base="Windows!Microsoft.Windows.ApplicationComponent" Hosted="true" Singleton="false" Extension="false">
              <Property ID="ServiceEMP" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" Scale="0" />
              <Property ID="ServiceDEPT" Type="string" AutoIncrement="false" Key="false" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" Scale="0" />
            </ClassType>
          </ClassTypes>
          <RelationshipTypes>
            <RelationshipType ID="ServiceWCF.Computer.ComputerRoleHostingService" Accessibility="Internal" Abstract="false" Base="System!System.Hosting">
              <Source ID="Source" MinCardinality="0" MaxCardinality="2147483647" Type="ServiceWCF.Computer.ComputerRole" />
              <Target ID="Target" MinCardinality="0" MaxCardinality="2147483647" Type="ServiceWCF.Computer.Service" />
            </RelationshipType>
          </RelationshipTypes>
        </EntityTypes>
      </TypeDefinitions>
      <Monitoring>
        <Discoveries>
          <Discovery ID="ServiceWCF.NewDiscovery" Enabled="true" Target="ServiceWCF.Computer.ComputerRole" ConfirmDelivery="false" Remotable="true" Priority="Normal">
            <Category>Discovery</Category>
            <DiscoveryTypes>
              <DiscoveryClass TypeID="ServiceWCF.Computer.ComputerRole" />
              <DiscoveryRelationship TypeID="ServiceWCF.Computer.ComputerRoleHostingService" />
            </DiscoveryTypes>
            <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.FilteredRegistryDiscoveryProvider">
              <ComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>
              <RegistryAttributeDefinitions>
                <RegistryAttributeDefinition>
                  <AttributeName>AppExists</AttributeName>
                  <Path>SOFTWARE\Service\ServiceName</Path>
                  <PathType>0</PathType>
                  <AttributeType>0</AttributeType>
                </RegistryAttributeDefinition>
                <RegistryAttributeDefinition>
                  <AttributeName>ServiceName</AttributeName>
                  <Path>SOFTWARE\Service\ServiceName\ServiceName</Path>
                  <PathType>1</PathType>
                  <AttributeType>1</AttributeType>
                </RegistryAttributeDefinition>
              </RegistryAttributeDefinitions>
              <Frequency>60</Frequency>
              <ClassId>$MPElement[Name="ServiceWCF.Computer.ComputerRole"]$</ClassId>
              <InstanceSettings>
                <Settings>
                  <Setting>
                    <Name>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Name>
                    <Value>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>
                  </Setting>
                  <Setting>
                    <Name>$MPElement[Name="ServiceWCF.Computer.ComputerRole"]/ServiceName$</Name>
                    <Value>$Data/Values/ServiceName$</Value>
                  </Setting>
                </Settings>
              </InstanceSettings>
              <Expression>
                <And>
                  <Expression>
                    <SimpleExpression>
                      <ValueExpression>
                        <XPathQuery Type="String">Values/AppExists</XPathQuery>
                      </ValueExpression>
                      <Operator>Equal</Operator>
                      <ValueExpression>
                        <Value Type="String">True</Value>
                      </ValueExpression>
                    </SimpleExpression>
                  </Expression>
                  <Expression>
                    <SimpleExpression>
                      <ValueExpression>
                        <XPathQuery Type="String">Values/Servicename</XPathQuery>
                      </ValueExpression>
                      <Operator>Equal</Operator>
                      <ValueExpression>
                        <Value Type="String">True</Value>
                      </ValueExpression>
                    </SimpleExpression>
                  </Expression>
                </And>
              </Expression>
            </DataSource>
          </Discovery>
        </Discoveries>
      </Monitoring>
      <LanguagePacks>
        <LanguagePack ID="ENU" IsDefault="true">
          <DisplayStrings>
            <DisplayString ElementID="ServiceWCF.Computer.ComputerRole">
              <Name>Service WCF Computer</Name>
              <Description />
            </DisplayString>
            <DisplayString ElementID="ServiceWCF.Computer.ComputerRole" SubElementID="ServiceName">
              <Name>Service Name</Name>
              <Description />
            </DisplayString>
            <DisplayString ElementID="ServiceWCF.Computer.Service">
              <Name>WCF Service</Name>
              <Description />
            </DisplayString>
            <DisplayString ElementID="ServiceWCF.Computer.Service" SubElementID="ServiceEMP">
              <Name>WCF Service Employee</Name>
              <Description />
            </DisplayString>
            <DisplayString ElementID="ServiceWCF.Computer.Service" SubElementID="ServiceDEPT">
              <Name>WCF Service Department</Name>
              <Description />
            </DisplayString>
            <DisplayString ElementID="ServiceWCF.NewDiscovery">
              <Name>New Discovery</Name>
              <Description>Description for the new discovery.</Description>
            </DisplayString>
          </DisplayStrings>
        </LanguagePack>
      </LanguagePacks>
    </ManagementPack>


    Thanks & Regards, Suresh Gaddam

    • Proposed as answer by Chinna2580 Tuesday, February 3, 2015 7:33 AM
    Thursday, January 29, 2015 9:17 AM
  • I found my answer myself,there is problem with the windows computer target,so i used windows server computer and i removed some unwanted stuff from the management pack and now it is working extremely fine..

    Thanks & Regards, Suresh Gaddam

    • Marked as answer by Suresh Gaddam Monday, February 2, 2015 10:59 AM
    Monday, February 2, 2015 10:59 AM