...Because someone's gotta tell the story...


To return to the main Blog List, click Full Blog Listing.


Site Updates

GCI: Finding files with multiple parameters

Monday, June 10, 2013 in Powershell (Views: 2142)
Another PS Quickie, but say you want to find all the .JPG files in a folder, in this example, c:\temp. However, you do not want to see file1.jpg or file2.jpg. Simply use the PowerShell script below. Of course, this can be used for any extension type. Also, the example below attempts to demonstrate case sensitivity doesn't matter.

One other thing to note. For those who don't know, the backtick (`) is there for readability. It also works when executing a PowerShell script as a line continuance, much like VB/VBScript with the &_ continuance.

gci -Path "C:\Temp" | ? `
{$_.Extension -eq ".JPG" `
-and $_.Name -ne "file1.JPG" `
-and $_.Name -ne "file2.jpg"}

Happy scripting.


Related Blogs You May Be Interested In:

To leave a comment, please log in and/or register.