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


Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language http://labelary.com/viewer.html The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...