Powershell – manage items based on a list

Reading Time: < 1 minute

As I like programming and as  I have had to simplify some “routines” over the years, I’ve decided to share some of my tips & tricks and pieces of code that I’ve used and re-used.

Of course, most of the time I have found those via searching on the web, so if by any chance you follow me, you might find them even more quickly 😉

– Copy from a list

I have had to separate a bunch of files based on an Excel list using several criteria.

Once you have the list, you could for example use the script excerpt below which applies a copy-item, based on a csv file.

assuming your csv looks like this :

Try this :

Import-Csv fileList1.csv | ForEach {Copy-Item “G:\Numbered\$($_.YourColumnName)” G:\Selections }

But if your csv has only 1 column without headers like this :

You should use Get-Content because it’s not really a csv file, your code should be :
Get-Content files.csv | ForEach {Copy-Item G:\Numbered\$_ G:\Selections }

Indeed the file type does not matter, this also works but here I am deleting files..
Get-Content list2.txt | ForEach {Remove-Item C:\Temp\crs\documents\$_ }

Leave Comment

Your email address will not be published. Required fields are marked *