Skip to content

Instantly share code, notes, and snippets.

@jeffpatton1971
Created April 23, 2015 21:35
Show Gist options
  • Save jeffpatton1971/081f2450a6509d08093e to your computer and use it in GitHub Desktop.
Save jeffpatton1971/081f2450a6509d08093e to your computer and use it in GitHub Desktop.
The script I use to create a sample Management Pack
Remove-Variable *
clear
$Mp = New-ManagementPack -ID 'ptech.LegatoNetworker' -Version '1.0.0.57' -Name 'Legato Networker MP'
Add-Reference -ManagementPack $Mp -Reference (New-Reference -ManagementPack $Mp -Alias MSDL -ID Microsoft.SystemCenter.DataWarehouse.Library -Version 6.1.7221.0 -PublicKeyToken 31bf3856ad364e35)
Add-Reference -ManagementPack $Mp -Reference (New-Reference -ManagementPack $Mp -Alias MSIL -ID Microsoft.SystemCenter.InstanceGroup.Library -Version 6.1.7221.0 -PublicKeyToken 31bf3856ad364e35)
Add-Reference -ManagementPack $Mp -Reference (New-Reference -ManagementPack $Mp -Alias SC -ID Microsoft.SystemCenter.Library -Version 6.1.7221.0 -PublicKeyToken 31bf3856ad364e35)
Add-Reference -ManagementPack $Mp -Reference (New-Reference -ManagementPack $Mp -Alias Windows -ID Microsoft.Windows.Library -Version 6.1.7221.0 -PublicKeyToken 31bf3856ad364e35)
Add-Reference -ManagementPack $Mp -Reference (New-Reference -ManagementPack $Mp -Alias System -ID System.Library -Version 6.1.7221.0 -PublicKeyToken 31bf3856ad364e35)
Add-ClassType -ManagementPack $Mp -ClassType (New-ClassType -ManagementPack $Mp -ID 'ptech.LegatoNetworker.Computer' -Base 'Windows!Microsoft.Windows.Computer' -Accessibility 'Public' -Comment 'po ta toes')
Add-Property -ManagementPack $Mp -Property (New-Property -ManagementPack $Mp -ClassType -ID Path -Key false -Type string) -ClassType
Add-Property -ManagementPack $Mp -Property (New-Property -ManagementPack $Mp -ClassType -ID Release -Key false -Type string) -ClassType
Add-Property -ManagementPack $Mp -Property (New-Property -ManagementPack $Mp -ClassType -ID Version -Key false -Type string) -ClassType
Add-ClassType -ManagementPack $Mp -ClassType (New-ClassType -ManagementPack $Mp -ID 'ptech.LegatoNetworker.LegatoServers' -Base 'MSIL!Microsoft.SystemCenter.InstanceGroup' -Comment 'Legato Instance Group')
Add-Discovery -ManagementPack $Mp -Discovery (New-Discovery -ManagementPack $Mp -ID ptech.LegatoNetworker.ServerDiscovery -Target 'Windows!Microsoft.Windows.Computer' -Enabled $true -ConfirmDelivery $false -Priority Normal -Remotable $true -Comment 'Discover Legato Networker properties using Windows Registry')
Add-DiscoveryClass -ManagementPack $Mp -DiscoveryClass (New-DiscoveryClass -ManagementPack $Mp -TypeID 'ptech.LegatoNetworker.Computer')
Add-Property -ManagementPack $Mp -Property (New-Property -ManagementPack $Mp -DiscoveryClass -TypeID 'ptech.LegatoNetworker.Computer' -PropertyID Path) -DiscoveryClass
Add-Property -ManagementPack $Mp -Property (New-Property -ManagementPack $Mp -DiscoveryClass -TypeID 'ptech.LegatoNetworker.Computer' -PropertyID Release) -DiscoveryClass
Add-Property -ManagementPack $Mp -Property (New-Property -ManagementPack $Mp -DiscoveryClass -TypeID 'ptech.LegatoNetworker.Computer' -PropertyID Version) -DiscoveryClass
Add-DataSource -ManagementPack $Mp -DataSource (New-RegistryDataSource -ManagementPack $Mp -ID 'ServerDiscoveryDS'-TypeID 'Windows!Microsoft.Windows.RegistryDiscoveryProvider' -Comment 'Datasource for Discovery' -ComputerName '$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$' -Frequency 120 -ClassID '$MPElement[Name="ptech.LegatoNetworker.Computer"]$')
Add-RegistryAttributeDefinition -ManagementPack $Mp -RegistryAttributeDefinition (New-RegistryAttributeDefinition -ManagementPack $Mp -AttributeName Path -Path 'SOFTWARE\Legato\NetWorker\Path' -PathType 1 -AttributeType 1)
Add-RegistryAttributeDefinition -ManagementPack $Mp -RegistryAttributeDefinition (New-RegistryAttributeDefinition -ManagementPack $Mp -AttributeName Release -Path 'SOFTWARE\Legato\NetWorker\Release' -PathType 1 -AttributeType 1)
Add-RegistryAttributeDefinition -ManagementPack $Mp -RegistryAttributeDefinition (New-RegistryAttributeDefinition -ManagementPack $Mp -AttributeName Version -Path 'SOFTWARE\Legato\NetWorker\Version' -PathType 1 -AttributeType 1)
Add-InstanceSetting -ManagementPack $Mp -InstanceSetting (New-InstanceSetting -ManagementPack $Mp -Name '$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$' -Value '$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$')
Add-InstanceSetting -ManagementPack $Mp -InstanceSetting (New-InstanceSetting -ManagementPack $Mp -Name '$MPElement[Name="ptech.LegatoNetworker.Computer"]/Path$' -Value '$Data/Values/Path$')
Add-InstanceSetting -ManagementPack $Mp -InstanceSetting (New-InstanceSetting -ManagementPack $Mp -Name '$MPElement[Name="ptech.LegatoNetworker.Computer"]/Release$' -Value '$Data/Values/Release$')
Add-InstanceSetting -ManagementPack $Mp -InstanceSetting (New-InstanceSetting -ManagementPack $Mp -Name '$MPElement[Name="ptech.LegatoNetworker.Computer"]/Version$' -Value '$Data/Values/Version$')
Add-Discovery -ManagementPack $Mp -Discovery (New-Discovery -ManagementPack $Mp -ID ptech.LegatoNetworker.GroupDiscovery -Target ptech.LegatoNetworker.LegatoServers -Enabled $true -ConfirmDelivery $false -Remotable $true -Priority Normal -Comment 'Dynamically populate a group with discovered Legato servers')
Add-DiscoveryRelationship -ManagementPack $Mp -DiscoveryRelationship (New-DiscoveryRelationship -ManagementPack $Mp -TypeID 'MSIL!Microsoft.SystemCenter.InstanceGroupContainsEntities' -Verbose) -Verbose
Add-DataSource -ManagementPack $Mp -DataSource (New-GroupDataSource -ManagementPack $Mp -ID 'GroupDiscoveryDS' -TypeID 'SC!Microsoft.SystemCenter.GroupPopulator' -RuleID '$MPElement$' -GroupInstanceId '$MPElement[Name="ptech.LegatoNetworker.LegatoServers"]$' -Comment 'Datasource for Group Discovery')
Add-MembershipRule -ManagementPack $Mp -MembershipRule (New-MembershipRule -ManagementPack $Mp -MonitoringClass '$MPElement[Name="ptech.LegatoNetworker.Computer"]$' -RelationshipClass '$MPElement[Name="MSIL!Microsoft.SystemCenter.InstanceGroupContainsEntities"]$')
Add-Expression -ManagementPack $Mp -Expression (New-Expression -ManagementPack $Mp -RegExExpression -ValueExpression '$MPElement[Name="ptech.LegatoNetworker.Computer"]/Path$' -Operator 'ContainsSubstring' -Pattern 'nsr')
$Mp.OuterXml
@jeffpatton1971
Copy link
Author

This works up to the discoveryrelationship portion, there are multiple DiscoveryTypes in the underlying XML so I need to find the one I want and then add it, perhaps filter by ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment