Hi, I have a requirement,
I have to write a powershell script with two input params, and this script should return true or false.
Parameter1: Path of a text file which contains a list of file names ( ex: a.txt, test.dll etc).
Parameter2: Search directory. (has folders and subfolders)
I have to search for the fileNames listed in the textfile(input paramater1) in the searchDirectory(parameter2). If any of the fileName exists in any of the (searchDirectory or its folders or subfolders) the script should return 1 else 0.
Please find my below code which is incomplete. Im not sure how to capture GetChildItem result to return 0 or 1.
Please help me with script to achieve the requirement. Thanks in advance.
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$textFilePath,
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[string]
$searchDirectory
)
foreach($FileName in [System.IO.File]::ReadLines($textFilePath))
{
Get-ChildItem -Path $searchDirectory -Filter $Filename -Recurse
}