Jump to content

Recommended Posts

Posted (edited)

Hi,

I found this script on the forum and need assistance adjusting it. i would like to make the prefix (highlighted in red) before the serial number a manual input. Any assistance would be really appreciated.

@echo offfor /f "tokens=*" %%f in ('wmic bios get serialnumber /value ^| find "="') do set "%%f"

Echo My Serial Number is %serialnumber%

Set NewPCName=NYCL-%SerialNumber%

for /f "tokens=*" %%f in ('wmic computersystem get name /value ^| find "="') do set "%%f"

Set OLDPCName=%Name%

Echo %NEWPCNAME%

Echo %OLDPCNAME%

if %NEWPCNAME% == %OLDPCNAME% (

GOTO END

) ELSE (

GOTO DEPOL

)

: DEPOL

echo This computer will be renamed from %OLDPCNAME% to %NEWPCNAME%

wmic computersystem where caption='%OLDPCNAME%' rename %NEWPCNAME%

echo This computer is scheduled to restart in 60 seconds

shutdown -r -t 60

timeout 55

:END

echo end

Edited by Dj869
Posted

So, if I have understood you correctly you would like an input and the name of the machine to be set to

INPUT-%SerialNumber%?

 

Do you mind this being a PowerShell script?

 

# Shutdown value in seconds
$shutdowntime = 60

# Getting prefix
$prefix = read-host -Prompt "Enter the prefix"

# Getting serial number
$serialnumber = get-ciminstance win32_bios | select-object SerialNumber
$serialnumber = $serialnumber.serialnumber

# Making new name
$newName = "$prefix-$($serial)"
# Removing any spaces as that would result in an invalid name (You could be more compex and remove any invalid characater)
$newName = $newName -replace '\s',''

# Prompting user of the serial and new name
write-host "Serial number is $serialnumber.  New device name will be: $newname"

# If the new name is the same as the current name do nothing, else make the change, prompt user about shutdown and start the restart command
if($newName -ne $env:Computername)
{
   Rename-Computer -NewName $newName -Force
   Write-host "The device will rebooted in $shutdowntime seconds..."
   shutdown -r -t $shutdowntime
} else {
   Write-Host "The device is already called: $env:computername..." -ForegroundColor green
}

 

If I have misunderstood or this does not work as expected (I have not been able to test it and just quickly knocked it up before bed) let me know and we can discuss it and fine tune it 😊

  • Thanks 1
Posted

You could do something like this

 

echo off

for /f "tokens=*" %%f in ('wmic bios get serialnumber /value ^| find "="') do set "%%f"

set /p id="Enter ID: "

Echo My Serial Number is %serialnumber%

Set NewPCName=%id%-%SerialNumber%

for /f "tokens=*" %%f in ('wmic computersystem get name /value ^| find "="') do set "%%f"

Set OLDPCName=%Name%

Echo %NEWPCNAME%

Echo %OLDPCNAME%

if %NEWPCNAME% == %OLDPCNAME% (

GOTO END

) ELSE (

GOTO DEPOL

)

: DEPOL

echo This computer will be renamed from %OLDPCNAME% to %NEWPCNAME%

wmic computersystem where caption="%OLDPCNAME%" rename "%NEWPCNAME%"

echo This computer is scheduled to restart in 60 seconds

shutdown -r -t 60

timeout 55

:END

echo end

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...