Reputation: 11
tried this
Get-ChildItem -Path P:\Users\SMarri\Desktop\testingPS -Recurse |? {($_.LastWriteTime -lt (Get-Date).AddDays(-1))} | move-item -destination "P:\Users\SMarri\Desktop\testing" ,"P:\Users\SMarri\Desktop\C"
Getting below error
Move-Item : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Destination'. Specified method is not supported.
At line:1 char:140
+ ... destination "P:\Users\SMarri\Desktop\testing" ,"P:\Users\SMarri\Deskt ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Move-Item], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.MoveItemCommand
Upvotes: 1
Views: 45
Reputation: 174435
You can chain multiple Move-Item
/Copy-Item
commands by using the -PassThru
parameter switch:
Get-ChildItem -Path P:\Users\SMarri\Desktop\testingPS -Recurse |Where-Object {
$_.LastWriteTime -lt (Get-Date).AddDays(-1)
} |Move-item -Destination "P:\Users\SMarri\Desktop\testing" -PassThru |Copy-Item -Destination "P:\Users\SMarri\Desktop\C"
-PassThru
causes Move-Item
to output the file after the move operation, making it available for Copy-Item
to copy.
Upvotes: 4