I wrote this script as a helper function to enable me to set email addresses on notification devices. I am using it to update the email address of the currently on call administrator. Note you will need the out-log function from here.
#opsMgrSetNotificationEmail.ps1
# 20090609 - cornasdf
# sets new email addresses on a notification device given an RMS, a Recipient, a Notification and an email. See syntax below
param(
$RMS,
$RecipientName,
$DeviceName,
$email,
$verbosity = 0
)
#load logging library
. ./cornasdflib.ps1
out-log "Starting OpsMgrSetNotificationEmail with $RMS, $RecipientName, $DeviceName, $email"
#Returning Syntax on bad parameter
if (($RMS -eq $null) -or ($RecipientName -eq $null) -or ($DeviceName -eq $null))
{
Write-Host ""
Write-Host "Syntax:";
Write-Host "opsMgrSetNotificationEmail -RMS <SERVER> -RecipientName <Name> -DeviceName <Name> -email <EMail> [-verbosity <0-3>]"
Write-Host ""
Write-Host "Where:"
Write-Host "-RMS: Name of Root management Server. `n Ex: 'RootManagementServer.contoso.com'";
Write-Host ""
Write-Host "-RecipientName: Name of Recipient as defined in Administration->Notifications->Recipients. `n Ex: 'Primary On Call'";
Write-Host ""
Write-Host "-DeviceName: Name of Device as defined in `n Administration->Notifications->Recipients->Notification Devices->Name. `n Ex: 'PrimaryOnCall Email'";
Write-Host ""
Write-Host "-email: Email address to set. `n Ex: 'hocsprimaryoncall@company.com'"
Write-Host ""
Write-Host "-verbosity [optional]: Depth of log messages you want to see, default is 0, critical only"
Write-Host ""
out-log "Invalid/incorrect arguments supplied... Exiting." 0
exit;
}
out-log "Load SDK assemblies" 2
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.OperationsManager")
out-log "Connect to Management group" 1
$ManagementGroup = New-Object Microsoft.EnterpriseManagement.ManagementGroup($RMS)
$ManagementGroup.Reconnect()
out-log ("Connected to " + $ManagementGroup.Name)
out-log "Getting Recipient " 1
$objRecipient = $ManagementGroup.GetNotificationRecipient($RecipientName)
out-log ("Found Recipient " + $objRecipient.Name)
if ($objRecipient -eq $null) {
out-log "No Recipients found with the name `'$RecipientName`', exiting..." 0
exit;
}
out-log "Getting Device" 1
$objDevice = $objRecipient.Devices | where {$_.Name -eq $DeviceName}
out-log ("Found Device: " + $objDevice.Name + ", With email: " + $objDevice.Address)
if ($objDevice -eq $null) {
out-log "No devices found with the name `'$DeviceName`', exiting..." 0
exit;
}
out-log "Setting Email to $email" 1
$objDevice.Address = $email
out-log "Updating/Commiting Changes"
$objRecipient.update()
out-log "Finished OpsMgrSetNotificationEmail"