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"
Hello,
ReplyDeleteExcellent post I am trying to use it only to collect information not to update anything so far. One question what is the line ". ./cornasdflib.ps1" doing"?
is it a folder? another script tio run?
Thanks,
Dom
Hi Dominique,
ReplyDeleteThe line you reference just sources my standard library of functions. In this script we are only using the out-log function which is linked in the blurb above the post. if you want, you can remove that line and any line that starts w/ out-log. If you do that, I recommend replacing them w/ write-hosts or similar so you can watch the progress.
Hello Cornasdf
ReplyDeleteThis is excellent, this is some thing missing in SCOM which I also need to do, to make it easy for people to put themselfs oncall (i.e. update the fixed address).
A couple of questions please as I am not a scripting guy.
1: Where can I download your "cornasdflib.ps1"
2: Can the script be enhanced to be able to use a lookup table, for example another text file with the names and email addresses of the operators in question, for example
1,John,John@email.com
2,Paul,Paul@email.com
3,Steve,Steve@email.com
then when the script is run it displays the above (or just the name second field). you select the name you want and the correponding email address is used to update the oncall entity in SCOM?
I would be very grateful for you help/advise on this.
Thanks you
ErnestBrant@Hotmail.co.uk