# The name of the file to look for.
$fileName = 'somefile.txt'
# Where to start looking (the current dir).
$dir = $PWD.ProviderPath
# Walk up the directory hierarchy until the first file whose name
# matches $fileName is found, and return that file's path.
# If no such file is found, $file is (effectively) $null.
$file =
do {
if (Test-Path -Type Leaf -LiteralPath ($file = "$dir/$fileName")) {
$file # output the path of the file found.
break # exit the loop
}
} while ($dir = Split-Path -LiteralPath $dir)
CLICK HERE to find out more related problems solutions.