Solved

Modify script to prompt user for string

Posted on 2011-09-29
4
298 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

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.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

691 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