'How can I use a foreach in Powershell on an array

I am querying a MySQL database and getting the only 2 columns I need alert_limit and customer_email. I am planning to be able to select each email individually with the alert limit value and use them as variables into a SMTP param.

Update: to answer Luuk's question I am using the SimplySql Powershell module. https://www.powershellgallery.com/packages/SimplySql/1.6.2

$query = Invoke-SqlQuery -query "SELECT distinct alerts.* FROM alerts, joblog Where alert_enabled=1 and joblog.customer_id=alerts.customer_id AND alert_limit;"  | select "alert_limit", "customer_email"

The result is:

alert_limit customer_email             
----------- --------------             
        150 [email protected] 
      12000 [email protected] 
      10000 [email protected]

I am trying to send an individual email to each customer_email with their alert)limit in the body as below:

$Parameters = @{
    ToAddress   = '$customer_email'
    FromAddress = "[email protected]"
    Subject     = "Credits"
    Body        = "your credits are bellow" '$alert_limit'

but I struggle to select individual entries. thanks



Solution 1:[1]

I have done it.

 ForEach($customer in $query) {

   $alert_limit= $customer.alert_limit
   $customer_email =  $customer.customer_email

$Parameters = @{
    ToAddress   ="$customer_email"
    FromAddress = "[email protected]"
    Subject     = "Credits"
    Body        = "your credits are below<br> $alert_limit"

}
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1