Solved

Modify script to prompt user for string

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Synchronize a new Active Directory domain with an existing Office 365 tenant
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.

705 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

21 Experts available now in Live!

Get 1:1 Help Now