Query Active Directory for User Details using Kix Script

Written by James McDonald

July 22, 2011

I used to maintain another file for user email signatures but that is really daft when you can store and maintain it in AD.

This is how to grab the users details from Active Directory using Kixtart Script.

$oADSysInfo = CreateObject("ADSystemInfo")
$strUser = $oADSysInfo.UserName
$oUser = GetObject("LDAP://" + $strUser)

$strPhone = $oUser.telephoneNumber
$strName = $oUser.FullName
$strTitle = $oUser.Title
$strMail = $oUser.mail
$strDepartment = $oUser.Department
$strCompany = $oUser.Company
$strStreet = $oUser.StreetAddress
$strPostalCode = $oUser.PostalCode
$strCity = $oUser.L
$strCountry = $oUser.Co
$strFax = $oUser.FacsimileTelephoneNumber
$strMobile = $oUser.Mobile
$strWeb = $oUser.wWWHomePage
$strDescription = $oUser.Description

; echo it to terminal
? $strUser ; this is the CN record
? $strPhone 
? $strName 
? $strTitle
? $strMail 
? $strDepartment 
? $strCompany 
? $strStreet 
? $strPostalCode 
? $strCity 
? $strCountry 
? $strFax 
? $strMobile 
? $strWeb 
? $strDescription

Here is the VB Script version


set oADSysInfo = CreateObject("ADSystemInfo")
strUser = oADSysInfo.UserName
set oUser = GetObject("LDAP://" + strUser)

strPhone = oUser.telephoneNumber
strName = oUser.FullName
strTitle = oUser.Title
strMail = oUser.mail
strDepartment = oUser.Department
strCompany = oUser.Company
strStreet = oUser.StreetAddress
strPostalCode = oUser.PostalCode
strCity = oUser.L
strCountry = oUser.Co
strFax = oUser.FacsimileTelephoneNumber
strMobile = oUser.Mobile
strWeb = oUser.wWWHomePage
strDescription = oUser.Description

' echo it to terminal
wscript.echo strUser 
wscript.echo strPhone 
wscript.echo strName 
wscript.echo strTitle
wscript.echo strMail 
wscript.echo strDepartment 
wscript.echo strCompany 
wscript.echo strStreet 
wscript.echo strPostalCode 
wscript.echo strCity 
wscript.echo strCountry 
wscript.echo strFax 
wscript.echo strMobile 
wscript.echo strWeb 
wscript.echo strDescription

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

You May Also Like…