Script to Change Computer Description Need to query computer service tag then modify description for funding
#1
Posted 24 March 2010 - 04:34 PM
#2
Posted 24 March 2010 - 06:20 PM
segujl, on 24 March 2010 - 04:34 PM, said:
What list? Where is it located (read from a network share perhaps)? In what format is it? CSV or whatever? Detailed infos required here: column order, formatting, is there a header row? etc. Ideally you'd provide us with a sample.
Getting the service tag is trivial (no need for wmic, vbscript has everything needed built-in -- in fact, ~95% of this whole thing is a simple copy/paste job, along with some minor changes to glue the parts together). Setting the description in the registry is also trivial, however, don't you want to set the description in active directory as well?
#3
Posted 25 March 2010 - 08:54 AM
I originally wanted the resource code to be changed in the description field so i could query it using SCCM but it would be nice to have the info in Active Directory as well. Hopefully it isn't to much more work. Also, is this code that i would call or include in our login script so that as machines are added to the csv file they can receive these changes upon user login?
I also found this vb code to get the service tag. Hope it helps
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For each objBIOS in colBIOS
WScript.StdOut.WriteLine objBIOS.SerialNumber
Next
Attached File(s)
-
Funding Source Codes_Example.txt (330bytes)
Number of downloads: 8 -
Servicetag_ResourceCode_example.txt (353bytes)
Number of downloads: 9
This post has been edited by gunsmokingman: 26 March 2010 - 10:25 AM
Reason for edit: Added Code Tags For Format Purpose
#4
Posted 26 March 2010 - 11:04 AM
Quote
Dim StrComputer :StrComputer = "."
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
'-> First Check To See If This File Exists
If Fso.FileExists("Funding_Source_Codes_Example.txt") Then
Dim Ch1, Ch2, Obj, Ts
For Each Obj In Wmi.ExecQuery("SELECT * FROM Win32_BIOS")
Ch1 = Obj.SerialNumber
Next
Set Ts = Fso.OpenTextFile("Funding_Source_Codes_Example.txt",1)
Do Until Ts.AtEndOfStream
Ch2 = Ts.ReadLine
If InStr(1,Ch2,Ch1,1) Then
MsgBox "Match Found" & vbCrLf & Ch1,4128,"Confirm Match"
End If
Loop
Else
MsgBox "Missing This File Can Not Be Found" & vbCrLf & _
Fso.GetAbsolutePathName( "Funding_Source_Codes_Example.txt") ,4128,"Error No File"
End If
#5
Posted 26 March 2010 - 11:50 AM
*query the service tag of the local machine
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS = objWMIService.ExecQuery _
("Select * from Win32_BIOS")
For each objBIOS in colBIOS
WScript.StdOut.WriteLine objBIOS.SerialNumber
Next
*check the servicetag_resourcedoe file and see if it is listed in column1
I'm not sure how to scipt this but the file would be located on \\do-staff-srv\techsupport$
*if it is listed in column 1, then i need it to change the computer description and add the resource code in column2 (if possible add the description in AD)
the registry key that needs to be modified is ([HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\LanmanServer\Parameters]" srvcomment"="RES-3550")
*if it is not on the list then it should just exit the script with no error message
Thanks. I appreciate any further help you can provide.
Attached File(s)
-
Servicetag_ResourceCode_example.txt (449bytes)
Number of downloads: 8
This post has been edited by segujl: 26 March 2010 - 12:58 PM
#6
Posted 26 March 2010 - 12:46 PM
Quote
Quote
#7
Posted 26 March 2010 - 12:57 PM
#8
Posted 27 March 2010 - 02:31 PM
It's only a matter of gluing 3 little snippets together anyway:
- get service tag from registry
- matching it with a line inside a simple text file
- setting a registry value
each snippet being already written for you for the most part. It's quick & trivial to do.
So here goes, and sorry for taking so long to get back to you. It's barely tested, and on Win7 x64 only. No error handling to speak of or anything fancy (could have matched it using a RegEx, could have added logging, you could fetch matches from a simple database instead or even a REST web service, etc). It should still work fine.
Sorry for having to attach it, but the [ code ] tag screws up lines (splits them in half), and the [ quote ] tags strip all indentation... You will have to rename it to .vbs obviously.
Edit, it looks like the line break thing is fixed, now it's only the colors that are a bit weird:
Option Explicit
On Error Resume Next
Const tsvfile = "\\Your-Server\Network-Share\Path\servicetag_resourcecode.txt" 'service tag -> resource file
const HKLM = &H80000002
Dim oWMI, oFSO, oReg, f, strTsv, colItems, objItem, strSvcTag, strRes, blnMatch
'get service tag
strSvcTag = ""
Set oWMI = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = oWMI.ExecQuery("SELECT * FROM Win32_BIOS")
For Each objItem In colItems
If (Not IsEmpty(objItem.SerialNumber) And Trim(objItem.SerialNumber) <> "") Then strSvcTag = objItem.SerialNumber
Next
If strSvcTag = "" Then WScript.Quit 'no service tag to work from
'find match in TSV file
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not(oFSO.FileExists(tsvfile)) Then WScript.quit 'no file to work from
Set f = oFSO.OpenTextFile(tsvfile, 1) 'ForReading
strTsv = f.ReadAll 'read the whole tsv file in one fell swoop to minimize I/O
f.Close
ColItems = Split(strTsv, vbCrLf)
blnMatch = false
strRes = ""
For Each objItem In ColItems
If left(objItem,len(strSvcTag)) = strSvcTag Then blnMatch = true
If blnMatch Then
strRes = right(objItem, len(objItem) - instr(objItem, chr(9)))
Exit For
End If
Next
If Not blnMatch Then WScript.Quit 'no match
'set description in registry
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
oReg.SetStringValue HKLM,"SYSTEM\CurrentControlSet\services\LanmanServer\Parameters","srvcomment",strRes
Attached File(s)
-
script.txt (1.44K)
Number of downloads: 18
#9
Posted 29 March 2010 - 04:46 PM
I am going to start using this tomorrow after i get the txt file with the service tags and resource codes together. I understood to save it as a plain txt file not a csv file. Is that correct?
Have a great evening.
#10
Posted 29 March 2010 - 06:01 PM
If the user accounts had sufficient permissions, then you could also set the computer description in AD (trivial to do, an extra 2 lines or so), but I wouldn't personally give the users these permissions. You could have another script that enumerates PCs from AD (trivial to do), runs the exact same WMI query to get the asset tag but against remote computers instead of locally, then matches it to a RES-xxxx tag (100% identical code), and sets it in AD (just run the script with an account that has sufficient permissions for this task). Although I would definitely prefer cscript here so you can do console output (show asset numbers & res tags; and also log them of course). Still quick and easy, but it would be a little trickier to test over here not having the same AD tree
segujl, on 29 March 2010 - 04:46 PM, said:
I'm going with the sample you provided us with, specifically: a TSV file (tab separated values a.k.a. tab delimited). It might not be obvious if you open the file with notepad but it's a tab character between both columns and not a space, hence the chr(9) in the script. If it was a CSV file then it would be a comma instead. So you export your list from excel as a TSV file, and change the extension to .txt, just like you have before. If you want to use a comma or a space, there's a couple lines where you'd have to change minor things.
If you'd rather use another file format (CSV, flat text file with spaces, any database, a web service, etc) or language just let me know
#11
Posted 26 July 2012 - 11:15 PM
can you update the script to change computer descraption from txt list of ip's or computer name's and custom descrpation foe each one
the list will be in server or any where you like or same folder , list type 'tab_separated_values' or any other
list will contain ip's and each ip will have new computer descraption
all this computer connect to domain and some win xp and some win 7
please can any one help me with it . i am nOOb
it will help alot
- ← WIMGAPI WIMMountImage Progressbar
- Programming (C++, Delphi, VB/VBS, CMD/batch, etc.)
- Need a vbs script. that will run an exe but wait 30 minutes before ins →



Help
Back to top









