Created
February 14, 2020 15:56
-
-
Save emnavarro02/88166ad8990a40bba63e6ea795749bb8 to your computer and use it in GitHub Desktop.
Search for a file stored in any directory defined in %PATH%
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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