$server will contain an object that has an OldName property and a NewName property - e.g., one line from the CSV file. It looks to me as if you’re using it correctly.
Mmm, well, let’s make sure the terminology is right ;).
Import-CSV produces a collection of objects. Each object represents one data row from the CSV. The objects have properties that correspond to the CSV’s header row.
$rows = Import-CSV something.csv
$rows will contain all the objects
foreach ($row in $rows) {
$row.myproperty
}
Goes through each object in $rows, placing one object at a time into $row. $row.myproperty accesses the value in the “MyProperty” column of the current CSV data row. In your example, those property values are being passed to the -ComputerName and -NewName parameters of the command you’re running. So, $server.oldname refers to “the OldName column of the current CSV data row.” $server represents a single object, and OldName has become a property of that object.
I’m a bit of a stickler for terminology, because things get confusing otherwise. Commands have parameters; objects have properties. Parameters are a way of feeding input to a command; properties contain values.
For anyone interested in easily renaming multiple computers using a CSV file without having to understand or learn powershell it may be worthwhile giving Netdom Rename Computer GUI a try. Although it doesn’t use powershell, Netdom can still get the job done and we have made it even more simple with a graphical user interface. All you need to do is import your CSV file, input your domain credentials and click Rename.