sted Posted February 3, 2012 Posted February 3, 2012 ive managed to write a script (well pinched and edited really) that when run dumps the computer name into a users active directory info. Currently it works but it dumps the info to description id like it to dump it in office but if i change description to office the script just bombs out Const ADS_PROPERTY_CLEAR = 1 Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("WScript.Network") strCompName = LCase(objNetwork.ComputerName) strUserDN = objSysInfo.userName Set objUser = GetObject("LDAP://" & strUserDN) ' Bind to the user object in Active Directory with the LDAP provider. objUser.Put "Description", (strCompName) '...add the computer name to Active Directory profile... objUser.SetInfo ' ...and save the changes. 1
plexer Posted February 3, 2012 Posted February 3, 2012 LDAP Attributes. Properties Active Directory Users Computers Distinguished name Ben 1
Steve21 Posted February 3, 2012 Posted February 3, 2012 Try physicalDeliveryOfficeName Edit - I'm slow Steve 1
mcrompton01 Posted March 4, 2012 Posted March 4, 2012 Hi sted, Thanks for the above script it has proved really useful for us we coupled it with a couple of things: Logoff script to clear this value Changed the AD schema to add a new option to the users right click in ADUC: Start VNC session We did find one limitation it could not get the client name when a user logs into our terminal servers. We have pinched and modified some functions that allow you to get the clientname. Thought I'd post it back in case you find it useful. '######################################################################################################################## '# VERSION HISTORY # '# # '# v1.00 - Log basic conputer name to AD based on '# http://www.edugeek.net/forums/windows/89800-help-logon-script-writing-active-directory.html # '# v2.00 - Now works with Terminal Server ClientName # '# # '######################################################################################################################## On Error Resume Next 'Define the Update AD attribute and define all variables Const ADS_PROPERTY_UPDATE = 2 Dim objSysInfo, objNetwork, strCompName, strUserDN, objUser, strClientName, strTerminalServerIdent 'Part of the computer name that is unique to terminal servers (e.g. XYZ-TS-00X) must be lower case. strTerminalServerIdent = "-ts-" 'Create the objects required to get required information Set objSysInfo = CreateObject("ADSystemInfo") Set objNetwork = CreateObject("WScript.Network") 'Set the variables required strCompName = LCase(objNetwork.ComputerName) strUserDN = objSysInfo.userName 'check if the computer name is a Terminal Server If Instr(strCompName,strTerminalServerIdent) > 0 then strClientName = clientName() If strClientName <> "" then strCompName = trim(strClientName) End If End If 'Connect to the user/computer AD path (Bind) Set objUser = GetObject("LDAP://" & strUserDN) 'Add the computer name to the Office AD value for the user and save it objUser.Put"physicalDeliveryOfficeName", Trim(Ucase(strCompName)) objUser.SetInfo 'Close/empty all the variables (tidy up) strCompName = "" strCompName = Null strUserDN = "" strUserDN = Null strClientName = "" strClientName = Null Set objSysInfo = Nothing Set objNetwork = Nothing Set objUser = Nothing '############# FUNCTIONS REQUIRED ######################### Function sessionNumber() Dim oShell, oExec, sOutput, iUserPos, iUserLen, iStatePos Set oShell = CreateObject("WScript.Shell") Set oExec = oShell.Exec("query session %username%") sOutput = LCase(oExec.StdOut.ReadAll) iUserPos = InStr(sOutput,LCase(oShell.ExpandEnvironmentStrings("%username%"))) iStatePos = InStr(sOutput,"active") iUserLen = Len(oShell.ExpandEnvironmentStrings("%username%")) sessionNumber = CInt(Trim(Mid(sOutput,iUserPos+iUserLen,iStatePos-iUserPos-iUserLen))) End Function Function clientName() Dim oShell Set oShell = CreateObject("WScript.Shell") On Error Resume Next If Err.Number = 0 Then clientName = LCase(oShell.RegRead("HKCU\Volatile Environment\"& sessionNumber() &"\CLIENTNAME")) Else clientName = "" End If End Function Mark!
sted Posted March 4, 2012 Author Posted March 4, 2012 no probs my main purpose for my script is so that i can quickly see the spec of a given pc so it seems sensible to shove it in ad as it is a database and keeps as much info in the same place as poss.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now