OK, so I've moved onto Powershell these days, but I thought I'd start my blog posting with one of my favourites. Its adapted from a great idea at http://www.microsoft.com/technet/scriptcenter/resources/qanda/apr05/hey0429.mspx and essentially makes the description field of your computer accounts dynamically populated.
Why might you want to do this you ask?
Well, have you ever needed to find a computer name easily without needing to get the user to find it out? This script if run at login will populate the description field of the computer account with: username, current AD site, make and model of machine, time logged in, e.g.
Joe Bloggs logged on in Paris using HP 6710b, 08:30.
Simply sort your computer accounts by the description column and hey presto easy to find the computer the user is logged into. Simple, but very effective.
I also used it to easily sort computers into separate OU's for laptops and desktops.
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
objSitename = objSysInfo.SiteName
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For Each objItem in colItems
strManufacturer = objItem.Manufacturer
strModel = objItem.Model
Next
strMessage = objUser.CN & " logged on in " & objSitename & " using " & strManufacturer & ", " & strModel & " " & Now & "."
objComputer.Description = strMessage
objComputer.SetInfo
(By the way you'll need to add the 'Write description' property on the OU(s) where your computer accounts reside to something like Authenticated Users.)
Showing posts with label vbscript. Show all posts
Showing posts with label vbscript. Show all posts
Wednesday, 13 February 2008
Subscribe to:
Comments (Atom)