I have a Powershell script that connects to a SQL database, queries a list of DISTINCT email addresses, and puts them in a variable $data. (To give a bit more background information, this is for an employee training tracking system I am working on, and this query pulls out the email addresses of all supervisors who have employees with expired training [training that needs to be renewed]).
The next part is what I need help with.
In Powershell, I need to iterate through each supervisor email address in $data, and generate another SQL query that returns a list of expired training items that that supervisor is in charge of. I do not need help with the SQL query, I can do that. I need help with the Powershell scripting part of it.
In the end, I need Powershell to email each supervisor a list of expired training items for employees that they are in charge of. My question is, how do I get Powershell to iterate through the supervisor email addresses, perform a query for each one (WHERE email@example.com'), and pass/store the queried list as a text argument/file so then I can email each supervisor?
If this question is too involved, just forget the final 'emailing each supervisor' part. If you can get me through the Powershell iterated querying part, I can ask another question about the actual email process later (or maybe figure it out myself).
Thanks in advance!