Solved

Modify script to prompt user for string

Posted on 2011-09-29
4
290 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

If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now