Powershell script to append an extension to a file, input from CSV

Posted by Jeremy on Server Fault See other posts from Server Fault or by Jeremy
Published on 2010-06-15T16:52:55Z Indexed on 2010/06/15 17:03 UTC
Read the original article Hit count: 281

Filed under:

Hi All,

All I need is to have an Excel list of file paths and use Powershell to append (not replace) the same extension on to each file.

It should be very simple, right? The problem I'm seeing is that if I go input-csv -path myfile.csv | write-host I get the following output:

@{FullName=C:\Users\jpalumbo\test\appendto.me} 
@{FullName=C:\Users\jpalumbo\test\append_list.csv} 
@{FullName=C:\Users\jpalumbo\test\leavemealone.txt}

In other words it looks like it's outputting the CSV "formatting" as well.

However if I just issue import-csv -path myfile.csv, the output is what I expect:

FullName
--------
C:\Users\jpalumbo\test\appendto.me
C:\Users\jpalumbo\test\append_list.csv
C:\Users\jpalumbo\test\leavemealone.txt

Clearly there's no file called "@{FullName=C:\Users\jpalumbo\test\leavemealone.txt}" and a rename on that won't work, so I'm not sure how to best get this data out of the import-csv command, or whether to store it in an object, or what.

Thanks!!

© Server Fault or respective owner

Related posts about powershell