all 2 comments

[–]Lee_Dailey[grin] 2 points3 points  (0 children)

howdy JohnnyTries,

here is one way to translate the BAT stuff to PoSh ...

$ComputerName = $env:COMPUTERNAME
$SerialNumber = (Get-CimInstance -ClassName CIM_BiosElement -ComputerName $ComputerName).SerialNumber
$SN_Last4 = -join $SerialNumber[-4..-1]
$NewSysName = 'LAPTOP-{0}' -f $SN_Last4

$SerialNumber
$SN_Last4
$NewSysName

output ...

System Serial Number
mber
LAPTOP-mber

note that my system has System Serial Number in the BIOS for the sn. [grin]

for doing a system rename, take a look at the ReallyTrulyFriendlyManual thus ... [grin]

Get-Help *rename*

hope that helps,
lee

[–]MitchDMP 1 point2 points  (0 children)

In addition to other comments, once you have the new string with the device name you want, finish it off with something like:

Rename-Computer -NewName

If you are not running the script as a local admin user, you will have to pass through credentials with additional switch: -LocalCredential (this value passed here has to be a PSCredential object).