Search code examples
powershellcmdrename

Script to rename pc to string+serial number


Im trying to write a simple script to rename each pc on the network to PC-RV- and the serial number. So for example PC-RV-DHXS970. I have found the article on how to rename a PC to the serial, ie. powershell rename-computer (gwmi win32_bios).serialnumber

However, I want to go a step farther and add the "PC-RV-" to the front of it. I have tryed: powershell rename-computer "PC-RV-"(gwmi win32_bios).serialnumber with no luck. Any help would be greatly appreciated.


Solution

  • Try this:

    $NewName = "PC-RV-$((gwmi win32_bios).serialnumber)"
    Rename-Computer -ComputerName 'OLDPCNAME' -NewName $NewName
    

    The gwmi call is wrapped in $() which evaulates the command within the string.