Some months ago I wrote a blog post about getting the SMTP addresses of a User CI. This can be helpful if you need this information in a Opalis/Orchestrator Runbook. Based on this article the question came up if it would be possible to do the reverse approach and get the User or Group CI if you have a specific mail address. I took this as an input for this blog post as it indeed is possible.
The following script is based on the SMlets, so make sure you have them installed. Let’s start …
**
Let’s start by importing the smlets Powershell module
import-module smlets
This is the mail address you’re interested in
$mailaddress = zehner@itnetx.ch
Now we need to get some classes
$userhaspreferencerelationship = get-scsmrelationshipclass –name system.userhaspreference$
$userpreferenceclass = get-scsmclass -name system.userpreference$
$userandgroupclass = get-scsmclass -name microsoft.ad.userbase
Now let’s get the notification endpoint that has the specified mail address
$notificationendpoints = Get-SCSMObject -class $userpreferenceclass | where{$_.targetaddress -eq $mailaddress}
This should not be the case, but it’s theoretically possible that a mail address is assigned to more than one CI. Therefore I’m using a for-each loop to get some information about the CI.
foreach($notificationendpoint in $notificationendpoints)
{
$displayname = (Get-SCSMRelationshipObject –Relationship $userhaspreferencerelationship | where{$_.targetobject -eq $notificationendpoint}).sourceobject
Get-SCSMObject -class $userandgroupclass | where{$_.displayname -eq $displayname} | select displayname,objectstatus,domain,distinguishedname
}
**
Not that easy, but the advantage you have is that you just have to copy this script and use it. Have fun
regards
Marcel
Good. But think what happens if you have 5-10 thousands users and group. Try to change query and use relationship criteria instead of where clause.
Happy New Year:)
Hey Anton
You’re correct. But as this is something that should no be used on a regular basis, I have chosen to use the “where” clause because this is easier to read. If I find some time, I will also post an optimized script that uses a filter.
regards
Marcel
I am wondering if I may be able to use this for a problem I am having. I have an analyst that sometimes sends in incidents from his gmail account. The system keeps creating a second user for him with that email address, and his incidents get split between the two “assigned to” users in all the views. Is there a way to associate two email addresses with one user config so that incidents from either address match up to him and do not create a secondary user?
Hey
Did you try to add the second mail address to the User CI?
Cheers
Marcel
Yes, but then he gets duplicate notifications (one to each address).