Skip to content

Instantly share code, notes, and snippets.

@emnavarro02
Created February 14, 2020 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emnavarro02/88166ad8990a40bba63e6ea795749bb8 to your computer and use it in GitHub Desktop.
Save emnavarro02/88166ad8990a40bba63e6ea795749bb8 to your computer and use it in GitHub Desktop.
Search for a file stored in any directory defined in %PATH%
Param(
[Parameter(Mandatory=$true)]
[string] $FileName
)
$x= "Path"
$path = (Get-Item env:$x).Value
$path = $path.Split(";")
$found = @()
foreach ($p in $path)
{
if (Get-ChildItem $p -Name -Filter $FileName)
{
$found += $p
}
}
if ($found.Count -gt 0){
Write-Host "File found in the following directories:"
$found
}
else{
Write-Host "File NOT found."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment