Bulk Rename-Item from CSV

Good evening everyone, hoping someone might be able to tell me where I am missing some logic here. The following script works when there is one item in the csv file. Whenever there is more than one item, it fails with “Rename-Item : Cannot convert ‘System.Object’ to the type ‘System.String’ required by parameter ‘Path’. Specified method is not supported.” The header “PointerToSource” is a CIFS file path that is accessible. Like I mentioned, it works great with a single row in the CSV file, but as soon as there are more than one row besides the header, it fails.

This is my first post, but I’ve been around and certainly appreciate all help I’ve gained from others postings.

$filenames = Import-Csv "H:\docs\111\import_d1.csv"            
foreach [$file in $filenames]            
{            
    $filepath = $filenames.pointertosource            
    $fileFirstname = $filenames.import_first_name            
    $fileLastname = $filenames.import_Last_name
   
    
    Rename-Item $filepath -NewName $filefirstname-$filelastname.tif

Respectfully,

Aaron Rouse

Hey there Aaron!

In your ForEach statement, change the references to $filenames to $file.

Sorry. Just realized that might be a little vague. Try this?

$filenames = Import-Csv “H:\docs\111\import_d1.csv”
foreach ($file in $filenames)
{
$filepath = $file.pointertosource
$fileFirstname = $file.import_first_name
$fileLastname = $file.import_Last_name

 Rename-Item $filepath -NewName $filefirstname-$filelastname.tif

}

This is actually something I do to myself all the time. :slight_smile:

Thanks for the reply! I should have a test on this sometime this morning.

Thanks much! The specified change was all I needed, and I’m well on my way to the nearly 100k file rename operations that had to take place. I’m still a noob, and I appreciate your time!

No problem Aaron! I’m still pretty new myself, but I try to help where I can. :slight_smile: