Solved

Modify script to prompt user for string

Posted on 2011-09-29
4
293 Views
Last Modified: 2012-06-21
I want to modify the below script so that instead of reading the serial tag to rename a computer, it will prompt me for what I want to use as the computer name the run the rest of the script to change the computer name.
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2¿)

‘Part 1 – Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery (“Select * from Win32_SystemEnclosure”)
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> “” Then exit For
Next

‘Part 2 – Assign computer name to serial/service tag number
Name = strSN

Set colComputers = objWMIService.ExecQuery (“Select * from Win32_ComputerSystem”)

For Each objComputer in colComputers
err = objComputer.Rename(name)

if err <> 0 then
wscript.echo “There was an error renaming the machine. Please restart, and try again.”
else
wscript.echo “Machine successfully renamed: ” & Name
end if

Next

Open in new window

0
Comment
Question by:lemonville
  • 3
4 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 36818469
Hi, just change this
‘Part 1 – Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery (“Select * from Win32_SystemEnclosure”)
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber
If strSN <> “” Then exit For
Next

‘Part 2 – Assign computer name to serial/service tag number
Name = strSN

Open in new window


to this:
strSN = InputBox("Enter new computer name:")

Open in new window


Regards,

Rob.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 36818474
Oops, sorry.  Change that first block to this:
name = InputBox("Enter new computer name:")

Open in new window

0
 
LVL 1

Author Comment

by:lemonville
ID: 36818479
And remove part 1?

Thanks!
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 36818587
Yes, replace the part 1 block that I put in the snippet, with just that one line.

Rob.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question