Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell more than one operations using pipe

My script looks for all the files in folder1 and checks if this file exist in folder2. if it exists then I want to delete the file from folder2 and move the file from Folder1 to folder3.

$folder1 = "D:\folder1"
$folder2= "D:\folder2"
$folder3 = "D:\folder3"

$a = Get-ChildItem $folder1 | select -ExpandProperty basename 

$a | foreach {  
     Get-ChildItem -Path $folder2 -filter *$_* -Recurse 
}

Now if I use pipe at the end of for each loop I can either delete or move but not both. How do I handle this situation?

like image 521
Rupesh Avatar asked Sep 13 '25 18:09

Rupesh


1 Answers

Neither move-item or remove-item output anything to the pipe. However both have a -PassThru switch parameter to allow further processing.

like image 199
Richard Avatar answered Sep 15 '25 15:09

Richard