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 *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Squarespace Image Export

To gain continued access to your Squarespace website images after cancelling your subscription you have several...

MySQL 8.x GRANT ALL STATEMENT

-- CREATE CREATE USER 'tgnrestoreuser'@'localhost' IDENTIFIED BY 'AppleSauceLoveBird2024'; GRANT ALL PRIVILEGES ON...

Exetel Opt-Out of CGNAT

If your port forwards and inbound and/or outbound site-to-site VPN's have failed when switching to Exetel due to their...