PowerShell: Remotely rename Windows Computers from CSV file

I recently setup a bunch of Windows 7 VDI systems for a customer.  They asked if they could rename them to a different naming convention.  I definitely didn’t want to have to login to each one or run psexec.  Thankfully with Windows Management Framework(a prerequisite) & Powershell this is very straight forward.

1st Step: Run Get-ADComputer with your desired filter and export to CSV file for use in step 3.  All of my new VDI systems contained the syntax “vdi” so I used this as my filter.
Get-ADComputer -Filter {Name -like “*vdi*”} | select-object Name | Export-Csv .\RenameComputers.csv -NoTypeInformation

csv-export
2nd Step:
Open your new CSV in Excel and add a new row called “NewName”, add the corresponding new computer names & save:
csv-edit
3rd Step:
Prompts for credentials used to connect to the machine remotely, imports the csv, runs the rename-computer cmdlet using the content Name & NewName from the CSV & renames the computer.

$cred = get-credential    
$Computers = import-csv .\RenameComputers.csv
foreach ($Computer in $Computers){
Rename-Computer -NewName $Computer.NewName -ComputerName $Computer.Name -DomainCredential $cred -Restart
}

About AJ McKean

Based in sunny Tauranga, New Zealand, AJ McKean is a Senior Systems Engineer in Mt Maunganui. With over 15 years of professional IT experience working in both New Zealand and the United States, he holds several certifications including MCSE(2000-2003), MCITP:Enterprise(2008), MCSA(2012), VMware VCP-DCV5.5, CompTIA A+ & is an HP Storage Architect. He is passionate about all things IT, especially virtualization, automation & cloud technologies.

Leave a Reply

Your email address will not be published. Required fields are marked *