‎02-17-2022 02:40 PM
‎03-29-2022 09:28 PM
cscript {actionpath}changeAdCompDesc.vbs {computer}
' Get computer object in AD
strComputer = WScript.Arguments(0)
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "SELECT distinguishedName FROM 'LDAP://dc=your-domain,dc=com' WHERE objectCategory='computer' and name = '" & strComputer & "'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName").Value
objRecordSet.MoveNext
Loop
Set objComputer = GetObject("LDAP://" & strDN)
' Input new AD computer description field
newDescription = InputBox("Please enter the new AD Computer Description: ", "New description")
If newDescription = "" Then
Wscript.Echo ("Invalid description and this script will quit.")
Wscript.Quit
End If
' Write to AD computer object
objComputer.Put "Description" , newDescription
objComputer.SetInfo
‎03-15-2022 10:22 PM
' This script changes a computer's description as well as registers it in active directory with the serial number and last logged in user.
' If you want this to update automatically, make this a logon script in group policy.
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshNetwork = CreateObject("WScript.Network")
Set WshShell = WScript.CreateObject("WScript.Shell")
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colsystemenclosure = objwmiservice.execquery("Select * from Win32_SystemEnclosure")
' Get Serial number
For Each objcomputer In colsystemenclosure
serialnumber = Trim(objcomputer.serialnumber)
Next
'get AD user
Set adsinfo = CreateObject("adsysteminfo")
Set adcomputer = GetObject("LDAP://" & adsinfo.ComputerName)
Set aduser = GetObject("LDAP://" & adsinfo.UserName)
username = aduser.cn
strcomputer = wshnetwork.computername
Set objwmiservice = GetObject("winmgmts:{impersonationlevel=impersonate}!\\" & strcomputer & "\root\cimv2")
Set colcomputer = objwmiservice.execquery("Select * from Win32_computersystem")
Set colcomputerdisk = objwmiservice.execquery("Select * from Win32_diskdrive")
Set coloperatingsystem = objwmiservice.execquery("Select * from Win32_OperatingSystem")
Set colsystemenclosure = objwmiservice.execquery("Select * from Win32_SystemEnclosure")
Set colmacid = objWMIService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID = 'Local Area Connection'")
'get model
For Each objcomputer In colcomputer
cpumanufacturer = objcomputer.manufacturer
cpumodel = Trim(objcomputer.model)
Next
' Get OS version
For Each objcomputer In coloperatingsystem
servicepack = objcomputer.servicepackmajorversion
osver = objcomputer.name
osver1 = Mid( osver, 18,3)
Next
'Pull the machine description. This can be formatted however you want. We use a "RM:" then a five letter description filled in with leading zeros.
desc = GetDesc()
'sets the information in AD
'adcomputer.put "description", "LU: " & username & ", PC: " & desc & ", OS: " & osver1 & ", Mod: " & cpumodel & ", SN: " & ucase(serialnumber)
'adcomputer.put "description", "LU: " & username & ", OS: " & osver1 & ", Mod: " & cpumodel & ", SN: " & ucase(serialnumber)
adcomputer.put "description", "" & username & ", OS: " & osver1 & ", Mod: " & cpumodel & ", SN: " & ucase(serialnumber)
adcomputer.Setinfo
'This bit sets the last logged on user as the "phonetic display name" in AD. It makes it easy to figure out what computer someone is talking about just by adding a column.
'adcomputer.put "msDS-PhoneticDisplayName", "Last User: " & username
'adcomputer.setinfo
Function GetDesc()
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT Description FROM Win32_OperatingSystem")
For Each objItem in colItems
desc = objItem.Description
Next
GetDesc = desc
End Function
Function GetUser()
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
user = objComputer.UserName
Next
GetUser = user
End Function
‎02-22-2022 12:56 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now