Search Documentation by Keyword

Get-Files

You are here:
← All Topics

Syntax

Get-Files is used internally by a number of other cmdlets to locate files.

Given a starting directory, Get-Files recursively examines it and all subdirectories for files whose names match one of the items on the -Include list (or all files if -Include is unspecified) but none on the -Exclude list.

Get-Files returns an array of paths to the resulting files, relative to -Dir.

Get-Files `
    [-Dir <string>] `
    [-Include <string[]>] `
    [-Exclude <string[]>]

Parameters

ParameterRDescription
PathThe directory to search for files. Relative paths will be resolved relative to the script execution path.

Default: $pwd

Example: -Path "./Setup"
IncludeA string array of RegEx patterns. If a file matches any of them, it will be included in the returned list unless it also matches an exclusion.

Example: -Include @("th.*", "\.includedextension")
ExcludeA string array of RegEx patterns. If a file matches any of them, it will be excluded from the returned list.

Example: -Exclude @("this|that", "\.excludedextension$")
×