0
votes

I'm trying to create a PowerShell script that I can run every single morning when my PC turns on that moves all my recently downloaded of type .x from a folder y to a destination z.

Get-ChildItem "D:\Temp Downloads" *.gp5, *.gp4, *.gp3, *.gpx, *.fuse -Recurse |
    ForEach-Object { Move-Item $_ -Destination "D:\Guitarpro tabs" -Force }

When I run that code, I get this error:

Get-ChildItem : Cannot convert 'System.Object[]' to the type 'System.String'
required by parameter 'Filter'. Specified method is not supported.
At line:1 char:14
+ Get-ChildItem <<<<  "D:\Temp Downloads" *.gp5, *.gp4, *.gp3, *.gpx, *.fuse -Recurse | ForEach-Object { Move-Item $_ -Destination "D:\Guitarpro tabs" -Force }
    + CategoryInfo          : InvalidArgument: (:) [Get-ChildItem], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,Microsoft.PowerShell.Commands.GetChildItemCommand
1
since you failed to tell the Get-ChildItem cmdlet what to DO with the patterns you gave it, it tried to fit things in where the default is ... the -Filter parameter is the most obvious ... and it DOES NOT accept a collection. please look at Get-Help Get-ChildItem -Parameter * for what the parameters are and what they will accept. [grin]Lee_Dailey
You probably meant Get-ChildItem "D:\Temp Downloads" -Include *.gp5, *.gp4, .... You also don't need ForEach-Object here. Just pipe Get-ChildItem directly into Move-Item: ... | Move-Item -Destination "D:\Guitarpro tabs" -Force.Ansgar Wiechers
@AnsgarWiechers That gives no errors but does not work eitherCeri Westcott
"Does not work" is not a problem description. How exactly did it "not work"? Does Get-ChildItem not list the files you want? Does Move-Item not move them? What does your modified code look like in the first place? Please edit your question to provide this information.Ansgar Wiechers
Get-ChildItem "C:\Users\Ceri\Documents" -Include *.gp5, *.gp4, *.gp3 | Move-Item -Destination "D:\Guitarpro tabs" -Force Does not move the filesCeri Westcott

1 Answers

0
votes
Get-ChildItem "D:\Temp Downloads" *.gp5, *.gp4, *.gp3, *.gpx, *.fuse -Recurse |
ForEach-Object { Move-Item $_.fullname -Destination "D:\Guitarpro tabs" -Force }

This should do it. You're trying to move objects instead of file names