Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Script to rename a computer based on letters in name

Status
Not open for further replies.

thec0dy

IS-IT--Management
Apr 16, 2010
41
US
Hello,

I am looking for a script that will allow me to check a computer's name to see if the name contains these first three characters (HGN) and if it does only rename the first three characters to (GGH) while keeping the rest of the computer name.

So we have a computer with name needing to be changed:
HGN-L-FK92FS1

That needs to be changed to:
GGH-L-FK92FS1


Thank you all!
 
Set WshShell = CreateObject("Wscript.Shell")
strComputerName = WshShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
Wscript.Echo "strComputerName = " & strComputerName
If Left(UCase(strComputerName), 3) = "HKG" Then
Wscript.Echo "found a match for first three letters, HKG"
'a little risky?
strComputerName = Replace(strComputerName, "HKG", "BNN")
Wscript.Echo "new computername = " & strComputerName
Wscript.Echo "now all you need to do is use netdom?"
Wscript.Echo "i wonder how many applications will stop working due to the name change?"
End If
Set WshShell = Nothing

I Hear, I Forget
I See, I Remember
I Do, I Understand

Ronald McDonald
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top