0

I've created a list of "top files" I need to migrate to a shared drive using the following command

$Files= Get-ChildItem -Recurse C:\Users\User\Documents\ -filter "*.txt" | sort LastWriteTime -Descending | select FullName | select -First 10

The output of which looks like:

> echo $Files
FullName
--------
C:\Users\User\Documents\doc1.txt
C:\Users\User\Documents\doc2.txt
C:\Users\User\Documents\doc3.txt
C:\Users\User\Documents\doc4.txt
C:\Users\User\Documents\doc5.txt
C:\Users\User\Documents\doc6.txt
C:\Users\User\Documents\doc7.txt
C:\Users\User\Documents\doc8.txt
C:\Users\User\Documents\doc9.txt
C:\Users\User\Documents\doc10.txt 

The issue I'm having is that for every file, I need to do two actions:

  1. Move it to a set location
  2. Create a shortcut, using the same filename and point it to the new location.

If this was bash, a simple 'for i in..." would work, but I'm lost when it comes to PowerShell

Additionally, when referencing it, there seem to be additional characters added to the list, such as:

@{FullName=C:\Users\User\Documents\doc1.txt} 

This seems to break anything I've been able to do thus far as it's unable to handle the extra (incorrect) characters)

To make the request more clear: What is the best method for looping through each item and doing 'x' action?

Numpty
  • 1,461
  • 5
  • 19
  • 28

0 Answers0