How do I get get-childitem to filter on multiple file types?

Solution 1:

dir .\* -include ('*.xsl', '*.xslt') -recurse

Solution 2:

I do not know why, but this one seems to be much faster:

dir .\ -recurse | where {$_.extension -in ".xsl",".xslt"}

Solution 3:

The "filters" *.xsl and *.xslt can be part of the path parameter as well. Path can take a string array:

Set-Location c:\topLevel
gci *.xsl, *.xslt -Recurse

Solution 4:

This is older, but it helped me write this script to update URL's in desktop and/or favorite shortcuts, so I thought I would share:

foreach ($link in GCI "$env:USERPROFILE\Desktop" | Where-Object {$_.extension -in '.lnk','.url'}) {
   $shell = New-Object -COM WScript.Shell
   $shortcut = $shell.CreateShortcut($link.FullName)
   $shortcut.TargetPath = $shortcut.TargetPath -replace "old-url.com","new-url.com"
   $shortcut.Save()
}

foreach ($link in GCI "$env:USERPROFILE\Favorites" | Where-Object {$_.extension -in '.lnk','.url'}) {
   $shell = New-Object -COM WScript.Shell
   $shortcut = $shell.CreateShortcut($link.FullName)
   $shortcut.TargetPath = $shortcut.TargetPath -replace "old-url.com","new-url.com"
   $shortcut.Save()
}