locked
Disable Generate Alert for all Monitors/Rules in a MP RRS feed

  • General discussion

  • I'm trying to override the Generate Alert propertie to False,

    For all the Unit Monitors that are True by default and also that theirs Generate Alert Propertie is set to True by default in a given MP.

    Problem is,
    When i't trying to debug my .ps1 script:

    $mps=Get-SCOMManagementPack -DisplayName "Microsoft SQL Server 2016 (Monitoring)"
    $overrideMp= Get-SCOMManagementPack -Displayname "Microsoft SQL Server 2016 (Monitoring) Disabled New"
    $Monitors= Get-SCOMMonitor -ManagementPack $mps | where {$_.XmlTag -eq "UnitMonitor" -and $_.Enabled -eq "True"}
    
    foreach($Monitor in $Monitors)
    {
    if($Monitor.AlertSettings.AlertOnState -eq $true)
    {
    $Target= Get-SCOMClass -id $Monitor.Target.id
    $overridname=$Monitor.name+".Override"
    $override = New-ObjectMicrosoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($overrideMp,$overridname)
    $override.Monitor = $Monitor
    $Override.Property = 'GenerateAlert'
    $override.Value = 'false'
    $override.Context = $Target
    $override.DisplayName = $overridname
    }
    }
    $overrideMp.Verify()
    $overrideMp.AcceptChanges()

    I get the following Error:

    You cannot call a method on a null-valued expression.

    At line:22 char:1

    + $overrideMp.Verify()

    + ~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

        + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.

    At line:23 char:1

    + $overrideMp.AcceptChanges()

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

        + FullyQualifiedErrorId : InvokeMethodOnNull


    What am i missing here?

    Also, is the a way for accomplish the same for rules?



    • Edited by Edwio Tuesday, March 27, 2018 1:09 PM
    Tuesday, March 27, 2018 1:06 PM

All replies

  • Hi There,

    You want to disable all Rule/Monitor for a MPs but why you are doing that big code here.... You can achieve this via the below script.

    $MPNAME = Read-Host ‘Enter the Managemant Pack Display Name’
    $OVerrideMPName = Read-Host ‘Enter the Unsealed Override MP Name’
    $MPSealed = Get-SCOMManagementPack -DisplayName $MPNAME
    $MPUnsealed = Get-SCOMManagementPack -DisplayName $OVerrideMPName
    $MPMonitor = Get-SCOMMonitor -ManagementPack $MPSealed
    Disable-SCOMMonitor -Monitor $MPMonitor -ManagementPack $MPUnsealed
    or you can visit these link for further clarity Link 1 And this one for Rule only Link 2 for rule and the last one with lots of theory Link 3 


    Cheers, Gourav Please remember to mark the replies as answers if it helped.

    Wednesday, March 28, 2018 4:12 AM
  • Hi There,

    You want to disable all Rule/Monitor for a MPs but why you are doing that big code here.... You can achieve this via the below script.

    $MPNAME = Read-Host ‘Enter the Managemant Pack Display Name’
    $OVerrideMPName = Read-Host ‘Enter the Unsealed Override MP Name’
    $MPSealed = Get-SCOMManagementPack -DisplayName $MPNAME
    $MPUnsealed = Get-SCOMManagementPack -DisplayName $OVerrideMPName
    $MPMonitor = Get-SCOMMonitor -ManagementPack $MPSealed
    Disable-SCOMMonitor -Monitor $MPMonitor -ManagementPack $MPUnsealed
    or you can visit these link for further clarity Link 1 And this one for Rule only Link 2 for rule and the last one with lots of theory Link 3 


    Cheers, Gourav Please remember to mark the replies as answers if it helped.

    He's not trying to disable the monitor he'e trying only to uncheck the "generate alert" field in the monitor/rule properties :)

    @Edwio: Please allow me some time to test this (over the weekend) and revert with my findings.

    Cheers


    Sam (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" wherever applicable. Thanks!)

    Wednesday, March 28, 2018 4:17 AM
  • Opps My Bad , i was miss that :P

    But for this you need to check this out :-

    Import-module operationsmanager
    
    New-SCOMManagementGroupConnection
    
     
    
    $mps=Get-SCOMManagementPack |?{$_.displayname -match "Microsoft SQL Server 2016 (Monitoring)"}
    
    $overrideMp= Get-SCOMManagementPack -Displayname "sql.Override"
    
    $Monitors=$mps|Get-SCOMMonitor |?{$_.xmltag -eq "UnitMonitor"}
    
     
    
    foreach($Monitor in $Monitors)
    
    {
    
    if($Monitor.AlertSettings.AlertOnState -eq $true)
    
    {
    
    $Target= Get-SCOMClass -id $Monitor.Target.id
    
    $overridname=$Monitor.name+".Override"
    
    $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($overrideMp,$overridname)
    
    $override.Monitor = $Monitor
    
    $Override.Property = 'GenerateAlert'
    
    $override.Value = 'false'
    
    $override.Context = $Target
    
    $override.DisplayName = $overridname
    
    }
    
    }
    
    $overrideMp.Verify()
    
    $overrideMp.AcceptChanges()
    Or you can this one as well for further information Blog Link  

    Let me know if any error further :)


    Cheers, Gourav Please remember to mark the replies as answers if it helped.


    • Edited by GouravIN Wednesday, March 28, 2018 4:31 AM
    Wednesday, March 28, 2018 4:27 AM
  • @Sameer Mhaisekar, Thanks for the help. i will be patiently waiting :)
    Wednesday, March 28, 2018 8:49 AM
  • Opps My Bad , i was miss that :P

    But for this you need to check this out :-

    Import-module operationsmanager
    
    New-SCOMManagementGroupConnection
    
     
    
    $mps=Get-SCOMManagementPack |?{$_.displayname -match "Microsoft SQL Server 2016 (Monitoring)"}
    
    $overrideMp= Get-SCOMManagementPack -Displayname "sql.Override"
    
    $Monitors=$mps|Get-SCOMMonitor |?{$_.xmltag -eq "UnitMonitor"}
    
     
    
    foreach($Monitor in $Monitors)
    
    {
    
    if($Monitor.AlertSettings.AlertOnState -eq $true)
    
    {
    
    $Target= Get-SCOMClass -id $Monitor.Target.id
    
    $overridname=$Monitor.name+".Override"
    
    $override = New-Object Microsoft.EnterpriseManagement.Configuration.ManagementPackMonitorPropertyOverride($overrideMp,$overridname)
    
    $override.Monitor = $Monitor
    
    $Override.Property = 'GenerateAlert'
    
    $override.Value = 'false'
    
    $override.Context = $Target
    
    $override.DisplayName = $overridname
    
    }
    
    }
    
    $overrideMp.Verify()
    
    $overrideMp.AcceptChanges()
    Or you can this one as well for further information Blog Link  

    Let me know if any error further :)


    Cheers, Gourav Please remember to mark the replies as answers if it helped.


    Its working fine , have you checked this to disable alert generation?

    Cheers, Gourav Please remember to mark the replies as answers if it helped.

    Wednesday, March 28, 2018 9:14 AM
  • @GouravIN sorry for the late response, thanks for the help.
    the script you wrote is doing the same, as my script.

    But i've also tried it and got the same error message:

    You cannot call a method on a null-valued expression.

    At line:22 char:1

    + $overrideMp.Verify()

    + ~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

        + FullyQualifiedErrorId : InvokeMethodOnNull

    You cannot call a method on a null-valued expression.

    At line:23 char:1

    + $overrideMp.AcceptChanges()

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : InvalidOperation: (:) [], RuntimeException

        + FullyQualifiedErrorId : InvokeMethodOnNull

    Wednesday, March 28, 2018 10:08 AM
  • Opppsss ....

    Please use this line in script $overrideMp= Get-SCOMManagementPack |?{$_.displayname -match "sql Override"} In place of this   $overrideMp= Get-SCOMManagementPack -Displayname "sql Override"

    and make sure you have created a new/old unsealed MP named sql Override

    Let me know still you have any roadblocks 



    Cheers, Gourav Please remember to mark the replies as answers if it helped.

    Wednesday, March 28, 2018 10:17 AM
  • @GouravIN changing the syntax of the line you wrote isn't the problem.
    please pay attention to the error messages. it seems that when im calling the verify and AcceptChanges i can't use null. but there isn't any info about this in microsoft documentation.


    • Edited by Edwio Wednesday, March 28, 2018 10:42 AM
    Wednesday, March 28, 2018 10:39 AM
  • This what i assume that there is no null function. Let me give some time will update soon here

    Cheers, Gourav Please remember to mark the replies as answers if it helped.

    Wednesday, March 28, 2018 10:49 AM
  • Hey, this looks right, but let me still ask you a stupid question.

    Have you created the $OverrideMp beforehand? There won't be anything to verify if there's nothing in there (as the error suggests).

    Cheers


    Sam (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" wherever applicable. Thanks!)

    Sunday, April 1, 2018 4:07 AM
  • Hey Sameer Mhaisekar, i've indeed created the $OverrideMP before running the script.
    is the script working for you at your lab?


    • Edited by Edwio Tuesday, April 3, 2018 1:50 PM
    Tuesday, April 3, 2018 1:49 PM