none
Trying to create and populate groups with powershell in Operations Manager 2012 R2 RRS feed

  • Question

  • I'm getting a "Processing the template failed. See inner exception for details." error when I call InsertCustomMonitoringObjectGroup against my management pack.  It's not sealed, and all that good stuff.  If I include the references from the formula, I get an error "Exception calling "InsertCustomMonitoringObjectGroup" with "2" argument(s): "The additional references provided collided with existing references in the management pack." (which is expected, because the references are already in the management pack).

    Any help would be appreciated.  I think  I'm about out of ideas.

    Relevant code follows:

    Import-Module OperationsManager
    New-SCManagementGroupConnection -ComputerName (Get-ADComputer -Filter { serviceprincipalname -like "adtserver/*" } -Properties serviceprincipalname -Server "$($env:USERDNSDOMAIN):3268" | Select-Object -First 1).DnsHostName -Credential $credential

    $server = @{"server"="$(Get-ADDomainController -Discover -DomainName $env:USERDNSDOMAIN | Select-Object -ExpandProperty hostname)"}
    $gcserver = @{"server"="$(Get-ADDomainController -Discover -Service "GlobalCatalog" | Select-Object -ExpandProperty hostname)"}
    $targetmpname = "Server.Group.TEST.MP"
    $targetmanagementpack = Get-SCOMManagementPack -Name $targetmpname

    $newReferences = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackReferenceCollection
    $newReferences.Add("Windows",(Get-SCOMManagementPack -Name Microsoft.Windows.Library))
    $newReferences.Add("InstanceGroup",(Get-SCOMManagementPack -Name Microsoft.SystemCenter.InstanceGroup.Library))

    $adgroup = Get-ADGroup "scom test group" -Properties members,managedby @server
    $managedby = Get-ADObject -Identity $adgroup.managedby -Properties displayname,mail @server

    $groupformula = '<MembershipRule><MonitoringClass>$MPElement[Name="Windows!Microsoft.Windows.Computer"]$</MonitoringClass><RelationshipClass>$MPElement[Name="InstanceGroup!Microsoft.SystemCenter.InstanceGroupContainsEntities"]$</RelationshipClass><Expression><SimpleExpression><ValueExpression><Property>$MPElement[Name="MicrosoftWindowsLibrary7585010!Microsoft.Windows.Computer"]/DNSName$</Property></ValueExpression><Operator>Equal</Operator><ValueExpression><Value>server9.domain.local</Value></ValueExpression></SimpleExpression></Expression></MembershipRule>'

    $scomgroup = Get-SCOMClassInstance -Name $managedby.objectguid.guid
    If (-not $scomgroup) {
        $CustomMonitoringObjectGroup = [Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObjectGroup]::new($targetmpname,$managedby.objectguid.Guid,"ManagedBy Group: $($managedby.DisplayName)",$groupformula)
        $defaultmanagementpack.InsertCustomMonitoringObjectGroup($CustomMonitoringObjectGroup)
        $scomgroup = Get-SCOMClassInstance -Name $_.group.managedby.objectguid.guid
    }

    Thursday, July 26, 2018 5:50 AM

Answers

  • Messing around with it some more, I figured out what was going on.  There are some odd undocumented constraints on what you can use for the value of the "name" value passed to InsertCustomMonitoringObjectGroup.  It can't be blank (which is not documented except in the error message when you try to call the method), it can't have spaces (not documented), it can't have dashes (not documented).  There are probably other constraints, but I can't find documentation anywhere.
    • Marked as answer by Jordan Mills Friday, July 27, 2018 12:00 PM
    Friday, July 27, 2018 12:00 PM

All replies

  • Can you provide us with more context? Where is this workflow supposed to run (management server? monitored agents?)

    How did you define your classes, your references?

    Maybe this blog could help you, even though it provides a VBS example instead of powershell

    Thursday, July 26, 2018 7:13 AM
  • Can you provide us with more context? Where is this workflow supposed to run (management server? monitored agents?)

    How did you define your classes, your references?

    Maybe this blog could help you, even though it provides a VBS example instead of powershell

    It's not a workflow.  Right now it's just a powershell script I'm running by hand on a computer with the operations manager console installed.  I want to make sure I can get it working at all before I try to put it in more constrained environments.

    I'm not sure what you mean by defining classes and references.  Powershell uses dynamic references and all of the references here are fully qualified by type name.  The code you see will run with completely on its own, assuming the activedirectory and operationsmanager powershell modules are available.  Assuming your SPNs are set right (at least the adtserver SPN is set for the OpsMgr server you want to target), and those modules are available, it should run in your environment with no modification.

    Thursday, July 26, 2018 12:54 PM
  • Hi,

    For this issue, Microsoft Scripting Center may help. We can contact them at:

    https://technet.microsoft.com/en-us/scriptcenter/bb410849.aspx

    Based on my personal experience, the following statement may possibly returns 2 arguments that leads to error.

    $CustomMonitoringObjectGroup = [Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObjectGroup]::new($targetmpname,$managedby.objectguid.Guid,"ManagedBy Group: $($managedby.DisplayName)",$groupformula)

    For how to use the InsertCustomMonitoringObjectGroup, we may refer to the following example:

    Programmatically Creating Groups
    https://blogs.technet.microsoft.com/brianwren/2008/11/18/programmatically-creating-groups/

    Hope the above information helps.

    -----------------------------------------------

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.
    Friday, July 27, 2018 6:37 AM
  • Hi,

    For this issue, Microsoft Scripting Center may help. We can contact them at:

    https://technet.microsoft.com/en-us/scriptcenter/bb410849.aspx

    Based on my personal experience, the following statement may possibly returns 2 arguments that leads to error.

    $CustomMonitoringObjectGroup = [Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObjectGroup]::new($targetmpname,$managedby.objectguid.Guid,"ManagedBy Group: $($managedby.DisplayName)",$groupformula)

    For how to use the InsertCustomMonitoringObjectGroup, we may refer to the following example:

    Programmatically Creating Groups
    https://blogs.technet.microsoft.com/brianwren/2008/11/18/programmatically-creating-groups/

    Hope the above information helps.

    -----------------------------------------------

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

    Thanks for the reply.  Ed at the scripting center would say that it all looks like valid powershell and that I should find an operations manager programming/scripting group to ask.  Did you even try the script?  The error that results would make it clear that there's no problem with the script itself.

    I also reviewed the second link, but it didn't really help.  

    Friday, July 27, 2018 12:00 PM
  • Messing around with it some more, I figured out what was going on.  There are some odd undocumented constraints on what you can use for the value of the "name" value passed to InsertCustomMonitoringObjectGroup.  It can't be blank (which is not documented except in the error message when you try to call the method), it can't have spaces (not documented), it can't have dashes (not documented).  There are probably other constraints, but I can't find documentation anywhere.
    • Marked as answer by Jordan Mills Friday, July 27, 2018 12:00 PM
    Friday, July 27, 2018 12:00 PM