On Aug 5, 12:59*am, sardinian_guy <gu...@xxxxxx-email.com> wrote:
> It's perfect Kiron, thanks.
> However I don't understand why it works without using foreach before
This feature is by design. Move-Item takes the values in $input and
loops through them.
From the documentation:
-------------------------- EXAMPLE 4 --------------------------
C:\PS>get-childitem -path . -recurse -include *.txt | move-item -
This command moves all of the text files from the current directory
and all subdirectories, recursively, to the C:\TextFiles directory.
The command uses the Get-Childitem cmdlet to get all of the child
items in the current directory (represented by the dot (.)) and its
subdirectories that have a *.txt file name extension. It uses the
Recurse parameter to make the retrieval recursive and the Include
parameter to limit the retrieval to *.txt files.
The pipeline operator (|) sends the results of this command to Move-
Item, which moves the text files to the TextFiles directory.
If files being moved to C:\Textfiles have the same name, Move-Item
displays an error and continues, but moves only one file with each
name to C:\Textfiles. The other files remain in their original
If the Textfiles directory (or any other element of the destination
path) does not exist, the command fails. The missing directory is not
created for you, even if you use the Force parameter. Move-Item moves
the first item to a file called "Textfiles" and then displays an error
explaining that the file already exists.
Also, by default, Get-Childitem does not move hidden files. To move
hidden files, use the Force parameter with Get-Childitem.