Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Duplicate alert emails when Customfield updated using Powershell

9 views
Skip to first unread message

Robert Fergus

unread,
Jul 14, 2009, 12:03:02 PM7/14/09
to
Hello,

I have a Powershell script that populates information in an alert’s
Customfield10. When the script modifies the Custom Field another email for
that alert is sent, but this does not occur if the custom field is manually
updated through the UI.

I want to find out how to stop duplicate emails from being sent when an
alert is updated using Powershell.

The get-alert cmdlet is used and the script calls the Alert "Update" method.

Thanks Robert Fergus

Marco Shaw [MVP]

unread,
Jul 14, 2009, 7:28:22 PM7/14/09
to
Check this:
http://www.pavleck.net/2008/09/scom-snippet-the-hidden-nag-mode/

"Robert Fergus" <Robert...@discussions.microsoft.com> wrote in message
news:FF4971CD-395F-4733...@microsoft.com...

Robert Fergus

unread,
Jul 17, 2009, 11:42:03 AM7/17/09
to

"Marco Shaw [MVP]" wrote:

Background:

In the environment I work in computers name are long, obfuscated and are
physically distributed around the world. We populate information to the
Active Directory computer accounts, as well as on the computer in the
“Computer Description” field. I created a custom management pack with a
custom computer class, which I could then use to add “custom”
Attributes\Discoveries such as the “Computer Description Field”. Custom
fields can not be updated in the rule of a sealed MP. But much more
importantly, class targeting is limited to the target class.

At first, it seemed Anders Bengtsson's UpdateCustomField Powershell script
was the answer to my problem except that “not all alerts populate the
NetBiosComputerName field” as it is well documented in the article. Needing a
total solution for all alerts I was able to solve the problem based off
Anders Bengtsson's script, and a blog from Mark Wolzak called “Rights in the
OpsMgr Shell”.

I have a developed script that works, however the script can trigger another
email. To avoid that situation I have to update the field with something, and
only collect alerts that have an empty custom field. I was hoping to get
advise on how I can not to have an update email sent.
####################
# Start Ops Mgr snapin
####################
$rootMS = 'RMS_Server_Name'

# Initializing the Ops Mgr 2007 Powershell provider
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
-ErrorVariable errSnapin ;
set-location "OperationsManagerMonitoring::" -ErrorVariable errSnapin ;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable
errSnapin ;
set-location $rootMS -ErrorVariable errSnapin ;
####################
# Define Class to gather property information
####################
$NewAlerts = Get-Alert -Criteria 'ResolutionState = 0'
$ComputerClass = get-monitoringclass -name:CUSTOM.WindowsServer.ExtendedClass

$ComputerDescription = Get-MonitoringClassProperty
-monitoringClass:$ComputerClass | where { $_.Name -eq 'ComputerDescription'}
###################
# Loop through open alerts with "PrincipalName" Populated with the Server's
name
###################

$colItemsPrincipal = $NewAlerts | where {$_.ResolutionState -eq '0'-and
$_.NetBiosComputerName -ne $()-and $_.CustomField10 -match "^$"}

if ($colItemsPrincipal -match "^$") {Write-Output "There are no
PrincipalName Alerts to update at this time"
} else {
ForEach ($objItem in $colItemsPrincipal) {
$AlertID = $ObjItem.ID
$alert = $NewAlerts | where {$_.Id -eq $AlertID}
$alert.CustomField10 = "$((get-monitoringobject
-monitoringclass:$computerClass | Where-Object {$_.DisplayName -eq
$objItem.PrincipalName}).getmonitoringpropertyvalue($ComputerDescription))."
$alert.Update("")
}
}
###################
# Next Loop through open alerts with MonitoringobjectDisplayName populated
with the Server's name
###################

$colItemsMonitoringobjectDisplayName = $NewAlerts | where
{$_.ResolutionState -eq '0'-and $_.NetBiosComputerName -eq $()-and
$_.CustomField10 -match "^$"}
if ($colItemsMonitoringobjectDisplayName -Match "^$") {Write-Output "There
are no MonitoringobjectDisplayName alerts to update at this time"
} else {

ForEach ($objItem in $colItemsMonitoringobjectDisplayName) {
$AlertID = $ObjItem.ID
$alert = $NewAlerts | where {$_.Id -eq $AlertID}
$alert.CustomField10 = "$((get-monitoringobject
-monitoringclass:$computerClass | Where-Object {$_.DisplayName -eq
$objItem.MonitoringobjectDisplayName}).getmonitoringpropertyvalue($ComputerDescription))."
$alert.Update("")
}
}
###
# Remove the Ops Mgr PSSnapin
###
Remove-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client
######################### End Script

Robert Fergus

unread,
Jul 17, 2009, 11:49:01 AM7/17/09
to
I sent part of an older version of the script

The line: $colItemsPrincipal = $NewAlerts | where {$_.ResolutionState -eq

'0'-and
$_.NetBiosComputerName -ne $()-and $_.CustomField10 -match "^$"}

Should be" $colItemsPrincipal = $NewAlerts | where {$_.NetBiosComputerName

-ne $()-and $_.CustomField10 -match "^$"}

And

The line:$colItemsMonitoringobjectDisplayName = $NewAlerts | where


{$_.ResolutionState -eq '0'-and $_.NetBiosComputerName -eq $()-and
$_.CustomField10 -match "^$"}

Should be $colItemsMonitoringobjectDisplayName = $NewAlerts | where
{$_.NetBiosComputerName -eq $()-and
$_.CustomField10 -match "^$"}

Marco Shaw [MVP]

unread,
Jul 17, 2009, 7:46:14 PM7/17/09
to
I'll read through this in more detail early next week...

Marco

> Background:

Marco Shaw [MVP]

unread,
Jul 26, 2009, 8:40:51 PM7/26/09
to
I'm sorry. I still haven't looked at this yet...

Marco

"Marco Shaw [MVP]" <marco.shaw@NO_SPAMgmail.com> wrote in message
news:uqnh3izB...@TK2MSFTNGP04.phx.gbl...

0 new messages