Hi

we currently use this script to add last logon information , make model, serial number to description box in AD. is it possible to add the OS and version to it at the end please.

On Error Resume Next

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colcomputersystem = objWMIService.ExecQuery("Select * from Win32_computersystem")
Set colBIOS = objWMIService.ExecQuery("Select * from Win32_BIOS")
For each objcomputersystem in colcomputersystem
Getcomputersystem = objcomputersystem.Model
GetComputerManufacturer = objcomputersystem.Manufacturer
Next
For each objBIOS in colBIOS
GetSerialNumber = objBIOS.SerialNumber
Next
Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName)
Dim sSiteName : sSiteName = objSysInfo.SiteName
If Err Then
	sSiteName = "Unknown"
	Err.Clear
End If
 
if LCase(GetComputerManufacturer)="lenovo" then
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystemProduct")
For Each objItem in colItems
strModel = "Lenovo " & objItem.Version
Exit For
Next
Getcomputersystem = strModel & " (" & Getcomputersystem & ")"
end if
Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem") 
For each objOS in colOSes
GetOS = objOS.caption
GetArch = objOS.OSArchitecture
Next
strMessage = "SN: " & GetSerialNumber & " ---  Last Logon : " & objUser.displayName & " @ " & Date & " - " & Left(Time,5) & " /  Model: " & Getcomputersystem & " / Site: " & sSiteName
objComputer.Description = strMessage
objComputer.SetInfo

thank you

5 Spice ups

OS has it’s own tab, why would you also want it in the description field?

Why VB instead of PowerShell?

What is the purpose of using the description field in AD specifically?

7 Spice ups

would suggest PowerShell also, VB Script is being depreciated in Windows.

VBScript deprecation: Timelines and next steps | Windows IT Pro Blog

6 Spice ups

in that case is it possible to have the OS tab showing as a column in AD.

we’re haveing a summer refresh of installing windows 11 education, so it will be good to see which computers we have completed in each OU?

we use the VB script as a logon script to add the info into the description field which is added as a column.

3 Spice ups

If you mean without loading the properties, no. It cannot be a column in the AD console.

but you can run a PowerShell command to output this periodically.

If you want something GUI - ADInfo free will can do this

4 Spice ups

“Win32_OperatingSystem” can be used instead of “Win32_ComputerSystemProduct” in a WMI query to get the OS details: “Caption”, and “BuildNumber” fields specifically. Seems redundant, since would already be in the operating system tab. I’d usually use the machine name to then lookup in my system inventory.

VBscript is being depreciated, so consider rewriting in PowerShell and then signing using code signing certificate issued by AD Certificate Services.

3 Spice ups

ad Info tool is really good

3 Spice ups

Thank you.

can anyone come up with a powershell script for the above VB Script that would add the information we need into the AD description field please.

3 Spice ups

Thanks Rod-IT. i will try the AD info tool. seems promising.

do you know how to turn the VBS script to a powershell logon script, seeing that its being depreciated.

kind regards

3 Spice ups

I do not, but I also wouldn’t be collecting this information to put it in an AD field in the same way you do.

You should have some form of inventory system, especially from an insurance perspective.

If you have less than 200 devices/clients, Vendors > Action1 will not only inventory your devices, including software installed, but give you patch management* capabilities including OS upgrades and update rings, this includes patching of 3rd party products.

The first 200 are FREE. If you have 210 devices, you would only pay for the 10 above the 200 for free.

I use it to fully automate patching in my home lab, and would use it for work if we didn’t already have something else in place.

*Note that if you’re using WSUS, it’s deprecated, so you’ll need to move at some point, anyway.

If you are happy with manual entry inventory, SnipeIT. It too is free.

3 Spice ups

Paste your script into copilot and ask it to convert it.

4 Spice ups

Also note that while it’s deprecated (not receiving any new features or enhancements) it is NOT EoL or EoS and there is no date for either of those set as of this post. In fact, it’s still available to setup in Server 2025.

3 Spice ups

So is SMB1.0 :slight_smile:

4 Spice ups

note its been best security practice to disable the running of VB Script (Windows Script Host) for years, Like since 2010, as it is often and easily exploited by malware.

4 Spice ups

Oh good! Didn’t we have an issue the other day where someone was suggesting they use that? :rofl:

3 Spice ups

Oh probably.

You can put it right up there with people who say turn of the firewall and other such fun tidbits.

4 Spice ups

Two

3 Spice ups

As they say, what happens once will happen again…so, I guess that was expected?

3 Spice ups