Skip to content

Instantly share code, notes, and snippets.

@maciakl
Last active July 1, 2022 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciakl/623f2a0dda4ee41c5910e5f32474a65c to your computer and use it in GitHub Desktop.
Save maciakl/623f2a0dda4ee41c5910e5f32474a65c to your computer and use it in GitHub Desktop.
@echo off
if "%1" == "elevated" goto start
powershell -command "Start-Process %~nx0 elevated -Verb runas"
goto :eof
:start
@echo off
cls
CALL :HEAD
CALL :COMPUTERNAME
CALL :SERVICETAG
SET SERVICETAG=%SERVICETAG:~0,7%
echo.
echo Computer Name: %COMPUTERNAME%
echo Service Tag: %SERVICETAG%
echo.
echo.
choice /M "Rename and reboot [R], or Quit [Q]" /C RQ
echo.
if %ERRORLEVEL% == 1 ( CALL :RENAME )
if %ERRORLEVEL% == 2 ( goto :eof )
goto :start
:HEAD
cls
echo.
echo Rename Helper
echo =============
echo.
goto :eof
:COMPUTERNAME
for /f "skip=1" %%i in ('wmic computersystem get name') DO (
SET COMPUTERNAME=%%i
goto :eof
)
:SERVICETAG
for /f "skip=1" %%i in ('wmic bios get serialnumber') DO (
SET SERVICETAG=%%i
goto :eof
)
:RENAME
powershell -Command "Rename-Computer -NewName %SERVICETAG% -Restart"
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment