Renaming a computer using WMIC and how to get around that aggravating “Invalid Global Switch” error

Renaming a computer using WMIC and how to get around that aggravating “Invalid Global Switch” error

  • Comments 3
  • Likes

I’m guessing Ned will insert something like “Hello, Warren here again”. [Nope – Ned]

The other day I was working with server core and wanted to rename my server. Recently I have been working more with WMIC to get data from the DFSR service so I thought why not try WMIC?

Renaming a computer with WMIC

To rename a computer we can use the “Rename” method of the “Win32_ComputerSystem” WMI class. The command looks like this:

WMIC ComputerSystem where Name=COMPUTERNAME call Rename Name=NewName

Don't forget to reboot as you will not be prompted to restart the system.

Netdom can do the same thing

Don’t forget that you can also rename a computer using Netdom. You may find the Netdom method more user friendly if you are just renaming one system. Using WMIC may come in handy if you need to script the renaming of several machines or just want show off your “skills” to coworkers.

325354 How To Use the Netdom.exe Utility to Rename a Computer in Windows Server 2003 - http://support.microsoft.com/default.aspx?scid=kb;EN-US;325354

Netdom is part of the Support Tools for Windows 2003. In Windows 2008 it is included in the OS install.

“Invalid Global Switch” error

I noticed while working with renaming a computer with WMIC I would sometimes get an “Invalid Global Switch” error. After digging a bit I found that WMIC does not handle special characters. If there are dashes in any of the names used the command will fail unless they are enclosed with quotes. Just so happens I always use dashes in my computer names. So if the command was formatted as shown below it would fail.

WMIC ComputerSystem where Name=COMPUTER-NAME call Rename Name=NewName

To get this command to run you would need to enclose the name in quotes

WMIC ComputerSystem where Name="COMPUTER-NAME" call Rename Name=NewName

This command also takes environment variables, so if you have been using SYSPREP and have computer names that are gross, you can save time by using the %computername% variable:

image

Happy computer renaming!

- Warren Allen Williams

  • PingBack from http://www.ditii.com/2009/02/20/rename-a-computer-using-wmic-how-to-get-around-invalid-global-switch-error/

  • I stumbled across this while trying to rename a Windows 7 machine using Powershell.  Powershell naturally doesn't know what %computername% is so I substituted that for $env:computername.  However, this resulted in an 'Unexpected switch at this level' error.

    Other functions found online for renaming a machine using the Win32_ComputerSystem results in a 1326 ReturnValue when run as the Administrator.

    Any ideas or suggestions?

  • There was once a PowerShell comdlet called Rename-Computer during . For reasons unexplained, it was removed during the beta process. WMI would be the way to go for local renames, or Rename-ADObject if trying to rename a computer's AD object.