I have developed a power shell script that will check if it matches atleast one keyword in a file and if not matches I will send an email to the users. Now I have to check the list of files in particular folder with .yaml extension and do the same task that I have developed. If none of the file matches the keywords I would terminate the script
I can get the list of files that I required from the path using Get-ChildItem "D:\Users\Phase1\BridgeConnect*" -recurse -exclude product.yaml I want to check each of the listed files with the keywords matching atleast one and if any file doesn't contain the words I should terminate it
$smtpServer = "smtp.xxxxx.com"
$smtpFrom = "hxxxx"
$smtpTo = "xxxxx"
$messageSubject = "Please configure your API with atleast $words"
$messageBody = "Your product is not published"
$SEL = Select-String -Path .\aventionsearch_1.0.0.yaml -Pattern $words
if ($SEL -ne $null)
{
echo matched
}
else
{
$smtp = New-Object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($smtpFrom,$smtpTo,$messagesubject,$messagebody)
Write-Error 'The key words are not matched in this file or may not exist' -ErrorAction Stop
}