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
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 atGet-Help Get-ChildItem -Parameter *
for what the parameters are and what they will accept. [grin] – Lee_DaileyGet-ChildItem "D:\Temp Downloads" -Include *.gp5, *.gp4, ...
. You also don't needForEach-Object
here. Just pipeGet-ChildItem
directly intoMove-Item
:... | Move-Item -Destination "D:\Guitarpro tabs" -Force
. – Ansgar WiechersGet-ChildItem
not list the files you want? DoesMove-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