I'm a powershell novice and need assistance with this script. I already created the CSV file with old name, new name in line 1 and the data of old name, new name starting in line 2. When I try running the script, I run into this error.
Script:
$Credential=Get-Credential
$Computers = Import-CSV -Path "C:\RenameComputer.csv"
ForEach ($comp in $Computers){
Rename-Computer -ComputerName $($comp.oldname) -NewName $($comp.newname) -domaincredential $Credential -force
Restart-Computer $($comp.oldname)
}
Error:
Cannot validate argument on parameter 'ComputerName'. The argument is null or empty. Provide an
argument that is not null or empty, and then try the command again.
At line:2 char:35
+ Rename-Computer -ComputerName $($comp.oldname) -NewName $($comp.n ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:)...