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
2nd Step:
Open your new CSV in Excel and add a new row called “NewName”, add the corresponding new computer names & save:
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
}