Gilly2003 Posted February 16, 2015 Posted February 16, 2015 Hi guys, Im just in the testing phase of implemented steds script to populate computer AD descriptions, however I have ran in to an issue. I have created a test OU, placed a single computer in it and placed the scripts as a GPO for windows startup BUT I am not getting anywhere with it and seeing as my experience is lacking in this I am unsure as to whether I have set it up right even!!! I delegated control of read and write descriptions to "domain computers" and "domain users" Any help?
halbaradkenafin Posted February 16, 2015 Posted February 16, 2015 Anything in the Event Log for the PC? Should be something showing up for start up GPOs and the scripts. Other option would be to throw in some output to a file on the C: to ensure the script is actually running and then you can figure out if it's the script or the startup process that is the problem.
linkazoid Posted February 16, 2015 Posted February 16, 2015 I'll post my script tomorrow as I modified Sted's one to display Model, HDD, RAM and Serial Number... I had to delegate Domain Computers - Read Description, Write Description to Computer Objects.. and setup the script to run as a startup script. My script ran fine when run manually, but I had to wait for AD to replicate and for the computers to pickup the GPO. This was making me think that it wasn't working..
Gilly2003 Posted February 16, 2015 Author Posted February 16, 2015 Yeah that could be my problem, just not giving it time to replicate lol although it has been on the OU for a good few hours now... Ill give it a go again tomorrow, if not would be nice to have a look at your version of the script linkazoid? I also have it outputting to a csv on the domain controller and that is not there, will give it more time and if not there by tomorrow we know its most likely the permissions or way I have set it up!
FN-GM Posted February 16, 2015 Posted February 16, 2015 You will need to delegate the rights in AD for it to work. Have you done this?
halbaradkenafin Posted February 16, 2015 Posted February 16, 2015 Yeah that could be my problem, just not giving it time to replicate lol although it has been on the OU for a good few hours now... Ill give it a go again tomorrow, if not would be nice to have a look at your version of the script linkazoid? I also have it outputting to a csv on the domain controller and that is not there, will give it more time and if not there by tomorrow we know its most likely the permissions or way I have set it up! Try outputting to a csv on the test PC. It could be that it doesn't have permissions to access the drive on the DC.
linkazoid Posted February 16, 2015 Posted February 16, 2015 (edited) Option Explicit On Error Resume Next Dim objRootDSE, objNetwork, objWMIService, objComputer Dim strComputer, strMake, strModel, strSerialNumber, strMacAddresses, strMemory, intMemory Dim colBIOS, objBIOS Dim colItems, objItem, strHDD Dim colNetworkAdapterConfiguration, objNetworkAdapterConfiguration Dim colComputerSystem, objComputerSystem Dim colPhysicalMemory, objPhysicalMemory Dim adoConnection, adoRecordset strComputer = "." strMemory = "" strMake = "" strModel = "" strSerialNumber = "" strMacAddresses = "" Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") If Not colComputerSystem Is Nothing Then For Each objComputerSystem In colComputerSystem strMake = objComputerSystem.Manufacturer strModel = objComputerSystem.Model Next End If Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS strSerialNumber = objBIOS.SerialNumber Next End If Set colItems = objWMIService.ExecQuery("Select * From Win32_DiskDrive") If Not colItems Is Nothing Then For Each objItem in colItems strHDD = objItem.Model Next End If Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next strMemory = (intMemory / 1024 / 1024 / 1024) & " GB" End If Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" If Err.Number <> 0 Then MsgBox "Connect Error: " & Err.Description WScript.Quit End If Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) objComputer.Put "description", "" &strModel & ", HDD: " & strHDD & ", " & strMemory & " RAM" & ", Serial: " & strSerialNumber objComputer.SetInfo End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If Save this as a .vbs and run manually. Refresh AD to see if the description has updated. If so, recheck your delegation and set this as a startup script. The script has some leftover bits from sted's mac address bit but works without any issues for us. Edited February 16, 2015 by linkazoid 1
sted Posted February 17, 2015 Posted February 17, 2015 sorry was busy yesterday and wasnt on in work hours if its not writing to ad odds on you need to delegate read/write description on the os's (or domain your call) that you have this active on to domain computers (personally again i dont like delegating control to default groups so i create a pcs group which contains domain computers) as to the csv odds on its either a typo in the file path or permissions. Run the script manually BUT rem out On Error Resume Next then if the script has issues it will fail rather than just carrying on regardless. The write to ad bit i did so long ago (probably 3 years) i honestly cant even remember how it works its just been copied and pasted over between versions
sted Posted February 17, 2015 Posted February 17, 2015 for what its worth last version i have of that script Option Explicit 'On Error Resume Next dim outputstring, computermodel, cpu, ram, hddcapacity, hddfree, serialno, macaddress, operatingsystem, csvoutput dim stcomputer, colitems, objItem, colcpu, colPhysicalMemory, objPhysicalMemory, intMemory, colDisks, objhdd dim colComputerSystem, colOperatingSystems, objOperatingSystem, colBIOS, objBIOS, colnicconfig, objnicconfig dim objwmiservice, hddtemp, weidata, colWSA, operatingsystemno, Lastuser, oreg, spath, svalue, strvalue, svaluename dim adoutputstring, adoRecordset, adoConnection, objRootDSE, objNetwork, objComputer, existing dim pcname, wshShell, strDirectory, strFile, objFSO, objFolder, objFile, objTextFile, myDateString dim colnet,objnet, linkspeed, objWMIService2 stcomputer = "." myDateString = Date() Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("winmgmts:\\" & stcomputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") set coldisks = objWMIService.ExecQuery("Select * From Win32_LogicalDisk") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") Set colnicconfig = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") Set colWSA = objWMIservice.ExecQuery("Select * From Win32_WinSAT") Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") Set wshShell = WScript.CreateObject( "WScript.Shell" ) Set objWMIService2 = GetObject("winmgmts:\\" & stComputer & "\root\WMI") Set colnet = objWMIService2.ExecQuery("SELECT * FROM MSNdis_LinkSpeed",,48) 'write file location pcname = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" ) strDirectory = "c:\Users\J Stead\Desktop\" strFile = pcname & ".csv" 'make-model For Each objItem In colItems computermodel= objItem.Manufacturer & " " & objItem.Model 'wscript.echo computermodel Next ' Create the File System Object Set objFSO = CreateObject("Scripting.FileSystemObject") 'cpu info For Each objItem in colcpu cpu = objItem.Name 'wscript.echo cpu Next 'ram If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next ram = (intMemory / 1024 / 1024 ) & " MB" 'wscript.echo ram End If 'hdd capacity for each objhdd in coldisks If objhdd.DeviceID = "C:" Then hddcapacity = int(objhdd.Size/1073741824) & " GB" hddfree = int(objhdd.freespace/1073741824) & " GB" 'wscript.echo hddfree end if next 'windows version For Each objOperatingSystem in colOperatingSystems operatingsystem = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion operatingsystemno = objOperatingSystem.Version 'wscript.echo operatingsystem Next 'serial no If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS serialno = objBIOS.SerialNumber 'wscript.echo serialno Next End If 'mac address(s) If Not colnicconfig Is Nothing Then For Each objnicconfig in colnicconfig If macaddress <> "" Then macaddress = macaddress & " - " End If macaddress = macaddress & objnicconfig.MACAddress 'wscript.echo macaddress Next End If 'windows experience operatingsystemno = Left( operatingsystemno, 3 ) if operatingsystemno >5.5 then 'vista+ For Each objItem in colWSA 'weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" weidata = "Overall -" & objItem.WinSPRLevel & " - CPU - " & objItem.CPUScore & " - Memory - " & objItem.MemoryScore & " - Graphics - " & objItem.GraphicsScore & " - Gaming graphics - " & objItem.D3DScore & " - hdd - " & objItem.DiskScore next else 'xp- weidata = "Overall -" & "na" & " - CPU - " & "na" & " - Memory - " & "na" & " - Graphics - " & "na" & " - Gaming graphics - " & "na" & " - hdd - " & "na" end if 'last user if operatingsystemno >5.5 then 'vista+ Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & stcomputer & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & stcomputer End If End If else 'xp- Const HKEY_LOCAL_MACHINE = &H80000002 Set oreg=GetObject("winmgmts:\\" & stComputer & "\root\default:StdRegProv") spath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon" svalue = "DefaultUserName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser=strvalue svalue = "DefaultDomainName" oreg.GetStringValue HKEY_LOCAL_MACHINE, spath, svalue, strValue lastuser = strvalue & "\" & lastuser end if 'Scans data for Net Speed For Each objnet in colnet 'Removes "slow/unused links" if objnet.NdisLinkSpeed/10 > 1000 then linkspeed= objnet.NdisLinkSpeed/10000 & " Mbps" & "-" & linkspeed '& "-" & objnet.NdisLinkSpeed/10000 & " Mbps" end if next 'concatanate data for output outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," csvoutput = pcname & "," & computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & hddfree & "," & serialno & "," & operatingsystem & "," & macaddress & "," & weidata & "," & Lastuser & "," & linkspeed &"," & myDateString &"," ' wscript.echo outputstring ' Check that the strDirectory folder exists If objFSO.FolderExists(strDirectory) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFolder = objFSO.CreateFolder(strDirectory) 'WScript.Echo "Just created " & strDirectory End If If objFSO.FileExists(strDirectory & strFile) Then Set objFolder = objFSO.GetFolder(strDirectory) Else Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Wscript.Echo "Just created " & strDirectory & strFile End If set objFile = nothing set objFolder = nothing ' OpenTextFile Method needs a Const value ' ForAppending = 8 ForReading = 1, ForWriting = 2 Const ForAppending = 2 Set objTextFile = objFSO.OpenTextFile _ (strDirectory & strFile, ForAppending, True) ' Writes result every time you run this VBScript objTextFile.WriteLine(csvoutput) objTextFile.Close If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) existing = objcomputer.Description if left (existing,1) = "#" and not right (existing,1) = "#" then outputstring = existing & " : " & outputstring & "#" if left (existing,1) = "#" and right (existing,1) = "#" then 'msgbox "data" wscript.quit end if if not objComputer.Description = outputstring then 'msgbox "diff" objComputer.Put "description", outputstring objComputer.SetInfo else 'msgbox "matches" end if End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If 1
Gilly2003 Posted February 17, 2015 Author Posted February 17, 2015 thanks guys linkazoid your script works when ran locally althought it would prefer it to display the last logged in user as well (not sure if thats easy to add in?) sted thanks also, this is the copy i was using. I have a feeling I have not set the delegation correctly, any of you have a guide handy or could bulletpoint it for me?
sted Posted February 17, 2015 Posted February 17, 2015 thanks guys linkazoid your script works when ran locally althought it would prefer it to display the last logged in user as well (not sure if thats easy to add in?) sted thanks also, this is the copy i was using. I have a feeling I have not set the delegation correctly, any of you have a guide handy or could bulletpoint it for me? right click on the domain/ou and click delegate control click next click add add the domain computers group click next create a custom task click next only the following objects in the folder and select computer objects click next untick the first box and tick the second box tick read and write description click next click finish - - - Updated - - - thanks guys linkazoid your script works when ran locally althought it would prefer it to display the last logged in user as well (not sure if thats easy to add in?) sted thanks also, this is the copy i was using. I have a feeling I have not set the delegation correctly, any of you have a guide handy or could bulletpoint it for me? last logged in is a pain as winxp/win7+ need different code to extract it iirc 1
Gilly2003 Posted February 17, 2015 Author Posted February 17, 2015 Great, thanks sted. yeah thought that might be the case for the last logged in user. I think date is a better one to add in as give's an indication on whether the machine is actually active on domain (some sloppy work in the business before I started) It should just be a case of adding varibaled and output in to linkazoid script?
sted Posted February 17, 2015 Posted February 17, 2015 Great, thanks sted. yeah thought that might be the case for the last logged in user. I think date is a better one to add in as give's an indication on whether the machine is actually active on domain (some sloppy work in the business before I started) It should just be a case of adding varibaled and output in to linkazoid script? its actually in my script variable name is lastuser its set to write it to csv in the example above just add & "," & Lastuser to the end of output string near the bottom
Gilly2003 Posted February 17, 2015 Author Posted February 17, 2015 (edited) well my VB skills are back in the uni days, getting an error with the below for adding the date in: Code: Option Explicit On Error Resume Next Dim objRootDSE, objNetwork, objWMIService, objComputer Dim strComputer, strMake, strModel, strSerialNumber, strMacAddresses, strMemory, intMemory Dim colBIOS, objBIOS Dim colItems, objItem, strHDD Dim colNetworkAdapterConfiguration, objNetworkAdapterConfiguration Dim colComputerSystem, objComputerSystem Dim colPhysicalMemory, objPhysicalMemory Dim adoConnection, adoRecordset Dim myDateString strComputer = "." strMemory = "" strMake = "" strModel = "" strSerialNumber = "" strMacAddresses = "" myDateString = Date() Set objRootDSE = GetObject("LDAP://RootDSE") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") If Not colComputerSystem Is Nothing Then For Each objComputerSystem In colComputerSystem strMake = objComputerSystem.Manufacturer strModel = objComputerSystem.Model Next End If Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS strSerialNumber = objBIOS.SerialNumber Next End If Set colItems = objWMIService.ExecQuery("Select * From Win32_DiskDrive") If Not colItems Is Nothing Then For Each objItem in colItems strHDD = objItem.Model Next End If Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next strMemory = (intMemory / 1024 / 1024 / 1024) & " GB" End If Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" If Err.Number <> 0 Then MsgBox "Connect Error: " & Err.Description WScript.Quit End If Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) objComputer.Put "description", "" &strModel & ", HDD: " & strHDD & ", " & strMemory & " RAM" & ", Serial: " & strSerialNumber & ", Date: " myDateString objComputer.SetInfo End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If Edited February 17, 2015 by Gilly2003
Gilly2003 Posted February 17, 2015 Author Posted February 17, 2015 scrap that last one I didnt realise the latest verison of steds script was different to what I thought I was using, its exactly what I need Thanks very much for help guys, I also tested it on a OU and it worked perfectly. Much appreciated.
Firefox Posted February 18, 2015 Posted February 18, 2015 We run this and gives us the last logged on user Script to change AD Object Description to local variables #$cred = Get-Credential $strName = $env:computername $CompSys = wmiobject -class win32_computersystem; $Nic = wmiobject -class win32_networkadapterconfiguration | where {$_.IPEnabled -eq "True"} $OS = wmiobject -class win32_operatingsystem $Mfacture = $CompSys.Manufacturer; $Model = $CompSys.Model; $CUser = $CompSys.UserName; $Name = $CompSys.Name; $IPv4 = $Nic.IPAddress[0]; $MAC = $Nic.MACAddress; $OSName = $OS.Caption; $Dom = $CompSys.Domain; $strFilter = "(&(objectCategory=Computer)(Name=$strName))" $objDomain = New-Object System.DirectoryServices.DirectoryEntry $objSearcher = New-Object System.DirectoryServices.DirectorySearcher $objSearcher.SearchRoot = $objDomain $objSearcher.PageSize = 1 $objSearcher.Filter = $strFilter $objSearcher.SearchScope = "Subtree" $colProplist = "name", "description" foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)} $colResults = $objSearcher.FindAll() foreach ($objResult in $colResults) {$objItem = $objResult.Properties $cname = $objitem.name $desc = $objItem.description $strDN = [string]$User.properties.Item("distinguishedName") } $OldCompDesc = $desc; $NewCompDesc = ("$CUser , $Name , $MAC , $IPv4 , $Mfacture $Model , $OSName") #Build LDAP DN Search $LDAPdn = ("$strDN") $namerem = ("$strName,") $LDAPdn = $LDAPdn.Replace("CN=","") $LDAPdn = $LDAPdn.Replace($namerem,"") $Target = [ADSI]"LDAP://$LDAPdn" if ($OldCompDesc -ne $NewCompDesc) { Function UpdateDesc($Parent) { ForEach ($Child In $Parent.Get_Children()) { If ($Child.Class -eq "Computer") { If ($Child.Name -eq $strName) { If ($Child.Description -ne $NewCompDesc) { $Child.Put("description", $NewCompDesc) $Child.SetInfo() } } } } } UpdateDesc $Target } #elseif ($OldCompDesc -eq $NewCompDesc){"No Change Required"}
Gilly2003 Posted February 23, 2015 Author Posted February 23, 2015 okay have to reopen this one I applied the changes for the script to run on one of our remote sites (still connected to our primary DC through a glorified central file server) however it doesnt seem to be attempting to even run, i.e. no csv in c drive and no description in AD. Now I have tested with my own PC on our primary site by putting it in the OU and it works fine so I know delegation is set correctly. Any ideas or options for me to investigate further?
sted Posted February 23, 2015 Posted February 23, 2015 take out the On Error Resume Next near the top and it will show you exactly where its failing (with it in if it finds an issue it just keeps on going until the end)
FragglePete Posted February 23, 2015 Posted February 23, 2015 I use the following script here, which does this in the description field of AD: Option Explicit On Error Resume Next Dim objRootDSE, objNetwork, objWMIService, objComputer, datastring Dim strComputer, strMake, strModel, strSerialNumber, strMacAddresses, strMemory, intMemory Dim colBIOS, objBIOS Dim colNetworkAdapterConfiguration, objNetworkAdapterConfiguration Dim colComputerSystem, objComputerSystem Dim colPhysicalMemory, objPhysicalMemory Dim adoConnection, adoRecordset dim mydatestring dim colOperatingSystems,objOperatingSystem,osver dim oReg, lastuser, snode, spath, svaluename, svalue dim colcpu, objItem, cpuspec dim objDisk, colDisks , cspace strComputer = "." strMemory = "" strMake = "" strModel = "" strSerialNumber = "" strMacAddresses = "" myDateString = Date() Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") Set colDisks = objWMIService.ExecQuery _ ("Select * from Win32_LogicalDisk") For Each objDisk in colDisks If objDisk.DeviceID = "C:" Then 'Wscript.Echo "DeviceID: " & objDisk.DeviceID cspace = int(objDisk.Size/1073741824) & " GB" end if Next Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colcpu = objWMIService.ExecQuery("Select * from Win32_Processor") For Each objItem in colcpu cpuspec = objItem.Name Next ' use "." for local computer sNode = "." Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE On Error Resume Next Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _ & sNode & "/root/default:StdRegProv") If Err.Number <> 0 Then On Error Goto 0 WScript.Echo "Could not connect to computer " & sNode Else On Error Goto 0 sPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI" sValueName = "LastLoggedonUser" If oReg.GetStringValue(HKLM, sPath, sValueName, sValue) = 0 Then lastuser = sValue Else lastuser = "unknown" & sNode End If End If Set objRootDSE = GetObject("[url]ldap://RootDSE[/url]") Set objNetwork = WScript.CreateObject("WScript.Network") Set objWMIService = GetObject("Winmgmts:\\" & strComputer & "\root\cimv2") Set colComputerSystem = objWMIService.ExecQuery("SELECT * FROM Win32_ComputerSystem") Set colOperatingSystems = objWMIService.ExecQuery _ ("Select * from Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems osver = objOperatingSystem.Caption & " sp " & objOperatingSystem.ServicePackMajorVersion'& " " & objOperatingSystem.Version Next If Not colComputerSystem Is Nothing Then For Each objComputerSystem In colComputerSystem strMake = objComputerSystem.Manufacturer strModel = objComputerSystem.Model Next End If Set colBIOS = objWMIService.ExecQuery("Select * From Win32_BIOS") If Not colBIOS Is Nothing Then For Each objBIOS in colBIOS strSerialNumber = objBIOS.SerialNumber Next End If Set colNetworkAdapterConfiguration = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") strMacAddresses = "" If Not colNetworkAdapterConfiguration Is Nothing Then For Each objNetworkAdapterConfiguration in colNetworkAdapterConfiguration If strMacAddresses <> "" Then strMacAddresses = strMacAddresses & ", " End If strMacAddresses = strMacAddresses & objNetworkAdapterConfiguration.MACAddress Next End If Set colPhysicalMemory = objWMIService.ExecQuery("Select * From Win32_PhysicalMemory") If Not colPhysicalMemory Is Nothing Then intMemory = 0 For Each objPhysicalMemory In colPhysicalMemory intMemory = intMemory + Int(objPhysicalMemory.Capacity) Next strMemory = (intMemory / 1024 / 1024) & " MB" End If Set adoConnection = CreateObject("ADODB.Connection") adoConnection.Provider = "ADsDSOObject" adoConnection.Open "Active Directory Provider" If Err.Number <> 0 Then MsgBox "Connect Error: " & Err.Description WScript.Quit End If Set adoRecordset = adoConnection.Execute(";(&(objectCategory=Computer)(name=" & objNetwork.Computername & "));adspath;subtree") If Err.Number <> 0 Then MsgBox "Query Error: " & Err.Description WScript.Quit End If If Not adoRecordset.EOF Then Set objComputer = GetObject(adoRecordset.Fields(0).Value) datastring = strmake & " " &strModel & " " & cpuspec & " " & strMemory & ", Serial No:" & strSerialNumber & ", MAC Addresses:" & strMACAddresses & osver if not objComputer.Description = datastring then 'msgbox "diff" objComputer.Put "description", datastring objComputer.SetInfo else 'msgbox "matches" end if End If If Err.Number <> 0 Then MsgBox "Write Error: " & Err.Description WScript.Quit End If I'm sure I got the script of this site quite some time ago. It also checks to see if the description is the same, if it is then it leaves it rather than re-writing which I believe can cause an issue. I only have it running for myself and the Techs so it gets nicely populated during the rebuild season (Summer Hols) - uses a GPO as a logon script. Pete
sted Posted February 23, 2015 Posted February 23, 2015 I use the following script here, which does this in the description field of AD: [ATTACH=CONFIG]29285[/ATTACH] ~snip~ I'm sure I got the script of this site quite some time ago. It also checks to see if the description is the same, if it is then it leaves it rather than re-writing which I believe can cause an issue. I only have it running for myself and the Techs so it gets nicely populated during the rebuild season (Summer Hols) - uses a GPO as a logon script. Pete again it looks like an older version of my script before one of the many rewrites to make it tidier/more efficient/easier to read 1
Gilly2003 Posted February 23, 2015 Author Posted February 23, 2015 hi sted, the script runs when i VNC on to the site and run manually it just does not run at startup now this site is in the sticks with a 2mb connection to us but i highly doubt thats the reason it wont run or even create a csv locally
TC-1927 Posted February 24, 2015 Posted February 24, 2015 Morning, I've been using a similar script which I got off here before. I think it was an older version, but it works like a charm so many thanks to whoever wrote it: Set WshNetwork = WScript.CreateObject("WScript.Network") Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") ' Get service tag and computer manufacturer For Each objSMBIOS in objWMI.ExecQuery("Select * from Win32_SystemEnclosure") serviceTag = replace(objSMBIOS.SerialNumber, ",", ".") manufacturer = replace(objSMBIOS.Manufacturer, ",", ".") Next ' Get computer model For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem") model = trim(replace(objComputer.Model, ",", ".")) Next ' Get computer object in AD Set objSysInfo = CreateObject("ADSystemInfo") Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) ' Build up description field data and save into computer object if different from current description ' We also do not update computers with a description that starts with an underscore (_) newDescription = WshNetwork.UserName & " (" & serviceTag & " – " & manufacturer & " " & model & ")" if not objComputer.Description = newDescription and not left(objComputer.Description,1) = "_" then objComputer.Description = newDescription objComputer.SetInfo end if Would anyone be able to tell me if there's a straightforward way of date stamping (not too worried about times, just DDMMYYYY) the description in AD when the users log in? Thanks!
Gilly2003 Posted February 25, 2015 Author Posted February 25, 2015 any thought guys. I test on our other remote site and still the same. Both these sites are controlled by a smaller DHCP server each which still sisters our domain controller in HQ through dedicated VPN's I logged on to these and in AD also delegated control and applied the GPO to no effect. As I say it works perfectly on site. Out of idea's??
sted Posted February 25, 2015 Posted February 25, 2015 Morning, I've been using a similar script which I got off here before. I think it was an older version, but it works like a charm so many thanks to whoever wrote it: Set WshNetwork = WScript.CreateObject("WScript.Network") Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") ' Get service tag and computer manufacturer For Each objSMBIOS in objWMI.ExecQuery("Select * from Win32_SystemEnclosure") serviceTag = replace(objSMBIOS.SerialNumber, ",", ".") manufacturer = replace(objSMBIOS.Manufacturer, ",", ".") Next ' Get computer model For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem") model = trim(replace(objComputer.Model, ",", ".")) Next ' Get computer object in AD Set objSysInfo = CreateObject("ADSystemInfo") Set objComputer = GetObject("LDAP://" & objSysInfo.ComputerName) ' Build up description field data and save into computer object if different from current description ' We also do not update computers with a description that starts with an underscore (_) newDescription = WshNetwork.UserName & " (" & serviceTag & " – " & manufacturer & " " & model & ")" if not objComputer.Description = newDescription and not left(objComputer.Description,1) = "_" then objComputer.Description = newDescription objComputer.SetInfo end if Would anyone be able to tell me if there's a straightforward way of date stamping (not too worried about times, just DDMMYYYY) the description in AD when the users log in? Thanks! again newer versions od my script do do that but only to the csv file its in the code just edit the 'concatanate data for output section and add mydate string to outputstring 'concatanate data for output outputstring = computermodel & "," & cpu &"," & ram &"," & hddcapacity& "," & serialno & "," & macaddress & "," & myDateString &"," any thought guys. I test on our other remote site and still the same. Both these sites are controlled by a smaller DHCP server each which still sisters our domain controller in HQ through dedicated VPN's I logged on to these and in AD also delegated control and applied the GPO to no effect. As I say it works perfectly on site. Out of idea's?? I honestly have no clue its a way in which ive never run it maybe try using the fqdn or ip of the server?
Gilly2003 Posted February 25, 2015 Author Posted February 25, 2015 I honestly have no clue its a way in which ive never run it maybe try using the fqdn or ip of the server? Is this where the 'LDAP://RootDSE' is, just deletew that line and add IP of DC? Sorry I am hopeless with VB
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