Skip to content

Instantly share code, notes, and snippets.

@zaqmor
Last active December 1, 2018 22:39
Show Gist options
  • Save zaqmor/3c010aa08515ed7bf18fe95241f1d27c to your computer and use it in GitHub Desktop.
Save zaqmor/3c010aa08515ed7bf18fe95241f1d27c to your computer and use it in GitHub Desktop.
Powershell: Find file structure object
# https://blogs.technet.microsoft.com/heyscriptingguy/2016/06/27/use-windows-powershell-to-search-for-files/
#
# -r : search recursively through subdirs
# -i "*pattern*" : include files matching pattern, can be used with exclude
# -i "*pattern*" : exclude files matching pattern, can be used with include
# -File : only find files, not dirs?
# -ErrorAction SilentlyContinue : ignore errors, generally, but includes specific minor errors such as files without permissions
# just find file via include
Get-Childitem –Path "C:\path\to\search" -recursive -File -include "*HSG*" -exclude "*.JPG,*.MP3,*.TMP"
aka
gci "C:\path\to\search" -r -File -i "*pattern*" -e "*.JPG,*.MP3,*.TMP"
# ... and to filter down to just full path (FullName), and not attributes
gci "C:\path\to\search" -r -File -i "*pattern*" | select-object FullName
# fast! best! only return full path as string
gci . -r -File -i "pattern-here" | select-object -expandproperty FullName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment