Need help with script to rename remote computers

I’ve been tasked with changing all computers in our environment to our new naming scheme “LT-<serialnumber> but there is no way I’m doing it manually. I’ve found a script that works, but as is it only reads from an answer file that has the old name and new name specified. That creates another challenge in that I’d have to query each remote machine individually to get it’s serial number and add it to the answer file. What I’d like to do is adjust the script so it will somehow run the command to pull the serial number from the BIOS and change the machine name to our format. The current script is as follows, words in all caps are what’s been redacted:

# Script to rename computers in a domain by parsing a CSV file # Assumes: File of names with a header row of OldName,NewName # and a row for oldname,newname pairs for each computer to be renamed. # Adjust filename and file path as appropriate. $csvfile = "C:FILE.CSV" Import-Csv $csvfile | foreach { $oldName = $_.OldName; $newName = $_.NewName; Write-Host "Renaming computer from: $oldName to: $NewName" netdom renamecomputer $oldName /newname:$newName /uD:DOMAINUSER /passwordD:PASSWORD /force 

submitted by /u/Hepatitis_420
[link] [comments]

Leave a Reply