This is my entire script so far. If the result of any of the Get-Content is TRUE, I need it to remove the $file.FullName file, run a batch script. Then I need it to loop back through the entire script to refresh the $files variable. I know this is a strange
one.
$path = "F:\PERSONAL\POWERSHELL\"
$files = Get-Childitem $path *.txt -Recurse | Where-Object { !($_.psiscontainer) }
$controls = Get-Content ($path + "\controlfile.rdl")
$output = $path + "\output.log"
$output2 = $path + "\output2.log"
$output3 = $path + "\output3.log"
Function getStringMatch
{
Foreach ($file In $files) # Loop through all *.txt files in the $path directory
{
If ($file.FullName -eq $path + "test.txt")
{
ForEach ($control In $controls) # Loop through the search strings in the control file
{
$result = Get-Content $file.FullName | Select-String $control -quiet -casesensitive
If ($result -eq $True)
{
$match = $file.FullName
"Test : $control in file : $match" | Out-File $output -Append
#Remove-Item $file.FullName #delete file for this section
#run batchfile to load data
#reloop this sequence
}#end of string if statement
} # end of search through control file
}
}
###################################################################################################################
elseif ($file.FullName -eq $path + "test2.txt")
{
ForEach ($control In $controls) # Loop through the search strings in the control file
{
$result = Get-Content $file.FullName | Select-String $control -quiet -casesensitive
If ($result -eq $True)
{
$match = $file.FullName
"Test2 : $control in file : $match" | Out-File $output2 -Append
}#end of string if statement
} # end of search through control file
}
##################################################################################################################
elseif ($file.FullName -eq $path + "test3.txt")
{
ForEach ($control In $controls) # Loop through the search strings in the control file
{
$result = Get-Content $file.FullName | Select-String $control -quiet -casesensitive
If ($result -eq $True)
{
$match = $file.FullName
"Test3 : $control in file : $match" | Out-File $output3 -Append
}#end of string if statement
} # end of search through control file
}
#####################################################################################################################
} #end of ForEach for the file
getStringMatch