$cs.File_FindFile
Description
Section titled “Description”Searches for files matching a name or wildcard pattern starting at searchroot, and returns the full paths of every match. Throws ArgumentNullException if filename is empty, and DirectoryNotFoundException if searchroot doesn’t exist.
Syntax
Section titled “Syntax”$cs.File_FindFile(string filename, string searchroot, bool recursive)
Parameters
Section titled “Parameters”filename (String)
Section titled “filename (String)”Name or wildcard pattern of the file(s) to search for, e.g. "*.log".
searchroot (String)
Section titled “searchroot (String)”Directory to start the search from. Must exist.
recursive (Boolean)
Section titled “recursive (Boolean)”$true to search searchroot and every subfolder beneath it; $false to search only searchroot itself.
Return value
Section titled “Return value”A list of strings containing the full path of every matching file. Returns an empty list (not $null) if nothing is found.
Example
Section titled “Example”$searchRoot = "C:\Users"if ($cs.File_ExistDir($searchRoot)){ $updateFiles = $cs.File_FindFile("update.exe", $searchRoot, $true) $cs.Job_WriteLog("Found $($updateFiles.Count) matching file(s)")}Recursively search a data folder tree for a specific log file left behind by the vendor installer:
$dataRoot = Join-Path $env:ProgramData "Contoso"if ($cs.File_ExistDir($dataRoot)){ $matches = $cs.File_FindFile("setup.log", $dataRoot, $true) foreach ($match in $matches) { $cs.Job_WriteLog("Found setup log at $match") }}Restrict the search to just the kit’s top folder (non-recursive) to locate the bundled MSI without descending into subfolders:
$kitRoot = Join-Path $global:Packageroot "kit"$msiFiles = $cs.File_FindFile("*.msi", $kitRoot, $false)if ($msiFiles.Count -eq 0){ Exit-PSScript -exitcode 1 -exitmessage "No MSI found directly under $kitRoot, aborting"}