0

I have a couple of questions. I have certain binaries in a folder...

F:\program files\application\Client\

I only want to copy the latest dll's that have a certain phrase in there names. Lets say "MVCsite". I know you can use Get-ChildItem -Filter with the filter parameters, to get just child items with a .dll extension, but is there a way to look for specific files with specific keywords, or am I going to have to literally copy a list of files out of the directory and move it to a back up folder? Is there a quick and dirty command to do that? As you can tell, I am new to powershell, but I am learning fast.

2
  • It there just a single keyword, or can there be more than one of them? Commented Jan 15, 2014 at 1:13
  • There can be more than one. Commented Jan 15, 2014 at 3:01

2 Answers 2

1

gci -path $path -filter "*.dll" | where {$_.Name -match "Keyword1|Keyword2|etc"}

Sign up to request clarification or add additional context in comments.

4 Comments

Get-ChildItem, same as you posted :) it can also be used as ls or dir
"-contains" won't work. I've taken the liberty of editing your answer. I hope you don't mind. Also it seems that there can be more than one keyword, so I've put those in too.
Can you have multiple -filter params? can you send an array to -filter?
Unfortunately not, it may only take a [string], not an array
0

Simply use wildcards in your -Path parameter:

Copy-Item F:\program files\application\Client\*MVCsite*.dll X:\DestinationDir

That will copy all files in F:\program files\application\Client\ whose names contain the string "MVCsite" and have the extension ".dll". Is that what you wanted to accomplish? If not, please clarify.

3 Comments

I guess technically I could just put an array into that -Path parameter If I new all the files I wanted to copy.
I don't understand the comment. Yes, you could do it that way, but putting that array together would be rather tedious. I thought the idea was to copy all files that have a certain extension and a certain string in their names. Are you trying to say that you think this solution requires you to list all the filenames individually? It doesn't. That one line copies all files that have "MVCsite" in the name and the ".dll" extension, all at once.
I know what you mean, I guess I was kind of 'thinking out loud' kindof, I was wondering if there was some kind of trade off, when I could simply just list all the files I need. But your answer is fine as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.