Ignition_Helpdesk
asked on
How to Programmatically get the @domain.com of an internal domain through a VB Script
I'm building a script I want to be able to execute on clients to create an OU in a domain, and create an account in that ou in the domain. This is not a problem.
The challenge is I'm trying to set the UPN property of these accounts. I can easily do this if I know the domain I'm working with, but I don't want to hardcode that into the script. I want the script to be able to figure out what the domain is and put into the proper formate for the attribute ,
The relevant portions of my script
The AD Bind
Set objRootLDAP = GetObject("LDAP://rootDSE" )
and the setting the account property
objUser.Put "userPrincipalName", strUser & "@" & objRootLDAP.Get("defaultNa mingContex t")
objUser.SetInfo
Assuming strUser is a varible which contacts the username to go into the UPN this unfortunately sets the UPN to something along the lines username@DC=domain,DC=com
What I need is username@domain.com
I thought maybe I could use WshNetwork and echo the Domain but this only returns Domain, and not Domain.com
Any thoughts?
The challenge is I'm trying to set the UPN property of these accounts. I can easily do this if I know the domain I'm working with, but I don't want to hardcode that into the script. I want the script to be able to figure out what the domain is and put into the proper formate for the attribute ,
The relevant portions of my script
The AD Bind
Set objRootLDAP = GetObject("LDAP://rootDSE"
and the setting the account property
objUser.Put "userPrincipalName", strUser & "@" & objRootLDAP.Get("defaultNa
objUser.SetInfo
Assuming strUser is a varible which contacts the username to go into the UPN this unfortunately sets the UPN to something along the lines username@DC=domain,DC=com
What I need is username@domain.com
I thought maybe I could use WshNetwork and echo the Domain but this only returns Domain, and not Domain.com
Any thoughts?
See the what I think is a similar question here https://www.experts-exchange.com/questions/25949165/Linking-to-Outlook-Contacts-from-Access.html
Basically passing the exchange username to the getsmtpaddress function and it will return the full smtp address that you can then process.
Chris
Basically passing the exchange username to the getsmtpaddress function and it will return the full smtp address that you can then process.
Chris
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
some of the answers provided would have worked, but not quite the way I wanted to get the information.
Open in new window
Something that might be a bit safer - is to get the environment variable USERDNSDOMAIN - it will show the user's domain in the format you'd like. Something like this would be nice:
Open in new window
Have fun!