Lately I've started working on automating some of my tasks. Since I work with windows machines mostly I decided to learn batch and powershell.
For now I have faced issue with variables in CMD.
The task is extremely simple. I want this script to change the hostname of the computer. The new name should be user input. I want it to find default hostname (whatever it is) and then change it to what I tell it to.
At this moment I was using command:
hostname
set /p future_name="Input what you want Hostname to be: "
wmic computersystem where caption='%computername%' rename %future_name%
shutdown /r /t 5
The tutorials that I keep finding say that the hostname of PC should already be written in the code. However, this script is being used on multiple machines which all bear different names.
I understand that this is a newbie question but I got stuck here.
C:\Windows\system32>wmic computersystem where caption='%computername%' rename 'future_name'
Executing (\\DESKTOP-SMTHSMTH\ROOT\CIMV2:Win32_ComputerSystem.Name="DESKTOP-SMTHSMTH")->rename()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{
ReturnValue = 87;
};
Press any key to continue...
P.S.
I tried running the script with another variable which will be me just retyping the hostname displayed above but it doesn't work still.
hostname
set /p my_name_is="Please retype my current name provided above: "
set /p future_name="Input what you want Hostname to be: "
wmic computersystem where caption='%my_name_is%' rename %future_name%
:: shutdown /r /t 5
PAUSE
It also returns the same as before. Any help will be appreciated!
ReturnValuereported in your above output suggests that you have, either specified an invalid character in your new name, or that new name exceeds the 63 characters limit.