VMware Cloud Community
sbeaver
Leadership
Leadership

Are you struggling to get the VM owners email address?

In my environment I was struggling a little to get the owners email address since the logon ID does not match the email address or even the correct domain so let my share what I have done and hopefully this might help someone else.

First off I get the Owner property and strip everything after the @ away which leaves me the login ID

ownerid = ownerName.split("@");

var ownerID = ownerid[0];

Now I have a powershell script to use WMI to get the email address but I was struggling to get this to work correct via vCO and the powershell plug in so I changed directions and uploaded the script to vCAC and used the designer to run the script on one of the workflowstubs and retrieve and store the email address of the user. See this post I used a guide http://cloudyautomation.com/2013/08/27/working-with-the-invoke-powershell-script-activity-in-vcac/

Below is the function I used to get the email address and what is loaded into vCAC

function GetEmail

{

$query = "Select * FROM ds_user where ds_sAMAccountName='$ownerID'"

$user = Get-WmiObject -Query $query -Namespace "root\Directory\LDAP"

$owner = $user.DS_mail

$Global:ownerEmail = "$owner"

}

GetEmail

Now I have the email address and have stored that value with the VM that I can call for any custom emails.

Cheers!!!

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
0 Kudos
6 Replies
stvkpln
Virtuoso
Virtuoso

I've only got a single AD domain to deal with from this perspective, so I was actually able to do the same sort of thing via the Active Directory Plugin for vCO... I wrote two actions to make it work -- needed to do this as two for various reasons. First one takes the userid coming in, strips everything post "@" and finds the AD:User object, and the second takes the AD:User object and parses out the email address. It's a lot cleaner (and quicker) than going and running a PowerShell script.

I can dig up the code from the actions on Wednesday when I'm back in the office if that'll make life easier. Smiley Happy

-Steve
0 Kudos
sbeaver
Leadership
Leadership

Steve,

That would be great and I would love to see the actions code.  I started looking at that method but was struggling creating the search part to come back with AD:User object.  Weakness in my coding skills Smiley Happy

Thanks

Steve

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
0 Kudos
stvkpln
Virtuoso
Virtuoso

I totally forgot to look the action up yesterday when I got to the office, but I did remember this morning while I was looking something else up! So... I'm going to hand over a few actions I use (they're separate because I end up chaining things off the AD:User object, so it's easier to get that object once, then re-use):

To get the AD:User when you know the userId you're looking for (since vCAC gives you that):

var userId = user.substring(0,user.indexOf("@"));

return ActiveDirectory.searchExactMatch('User',userId)[0];

user is the in attribute (i.e. user@domain), and the return type on the action is AD:User, What I did was basically create a value called userId that parses out the user from the domain, taking the substring from the beginning of user to the @ symbol. Then, using the ActiveDirectory plugin, I can do a searchExactMatch for the user... which, oddly, still returns the value as an array, so you need to have the [0] in there (ugh). It's simple, but very effective.

From there... You can pull out all sorts of values. For the email address, it's a single line of code:

return user.getAttribute('mail')

Or to return the full name (for custom attributes in vCenter, I want it in the format of First Last):

return user.getAttribute('givenName')+" "+user.getAttribute('sn');

I typically chain these actions off one another in a scriptable task. Of course, this all assumes you only have to worry / use one AD -- which is my case for these purposes.

If you go to vCO Team, they have a great article on actually pulling all of these values from the AD:User object. The link is:  How to get Active Directory User Attributes

-Steve
0 Kudos
sbeaver
Leadership
Leadership

That worked great!!!  Thanks Steve and BTW great name!!

Steve

Steve Beaver
VMware Communities User Moderator
VMware vExpert 2009 - 2020
VMware NSX vExpert - 2019 - 2020
====
Co-Author of "VMware ESX Essentials in the Virtual Data Center"
(ISBN:1420070274) from Auerbach
Come check out my blog: [www.virtualizationpractice.com/blog|http://www.virtualizationpractice.com/blog/]
Come follow me on twitter http://www.twitter.com/sbeaver

**The Cloud is a journey, not a project.**
0 Kudos
stvkpln
Virtuoso
Virtuoso

Nice! Glad that worked for you; I use it to populate requester / owner info into vCenter, along with custom emails that go out at the end of the build or decomm actions... Very useful to populate direct through vCO. Smiley Happy

-Steve
0 Kudos
gbeke
Enthusiast
Enthusiast

@stvkpin

I know this is an old thread, but I'm struggling with getting the email of the requesting user so that I can send the user an email at the end of a workflow. i found this and think it might be what I need but being very new to both vco and javascript I was wondering if you could share some more information on the actions you have created to get the email address the requesting user. What parameters (if any) do you have and of what type in the actions? Also I would greatly appreciate any example of how you use it to send email you might provide.

Thanks.

0 Kudos