Home > Scripting > KiXtart script to retrieve Active Directory user info

KiXtart script to retrieve Active Directory user info

August 21st, 2008 Leave a comment Go to comments

Here's a quick script written using KiXtart to retrieve information for a user (object) in Active Directory. Once enumerated, object information is stored in variables to be used later.

The organisation I work for has an application that requires each user’s telephone extension. So I use this script to retrieve the user’s telephone extension (from the Active Directory Telephone number attribute) during logon. It then writes that value to the appropriate registry key required by the application. This way all I have to remember to do when creating a new user or changing the users telephone is to set/change the 'Telephone number' attribute on the users account using the Active Directory Users and Computers MMC.

Here's the script:

;Retrieve Active Directory user information
$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)

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

As an example, here is how I could now write an Active Directory attribute to the registry, checking for some form of its existence before hand:

IF NOT $strPhone = ""
WRITEVALUE("HKCU\Software\MyTelephoneApp", "TelephoneNo", $strPhone, "REG_SZ")

Categories: Scripting Tags: , ,
  1. No comments yet.