To what CI belongs a specific mail address?

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 Smiley

regards
Marcel

About Marcel Zehner

Microsoft Azure MVP
This entry was posted in SCSM and tagged , , , , , , , . Bookmark the permalink.

5 Responses to To what CI belongs a specific mail address?

  1. FreemanRu says:

    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:)

    • Marcel Zehner says:

      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

  2. Audrey says:

    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?

    • Marcel Zehner says:

      Hey

      Did you try to add the second mail address to the User CI?

      Cheers
      Marcel

      • Audrey says:

        Yes, but then he gets duplicate notifications (one to each address).

Leave a Reply to Marcel Zehner Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s