[英]How can I use a foreach in Powershell on an array
我正在查詢 MySQL 數據庫並獲取我需要的僅有的 2 列 alert_limit 和 customer_email。 我計划能夠分別使用警報限制值 select email,並將它們用作 SMTP 參數的變量。
更新:為了回答 Luuk 的問題,我正在使用 SimplySql Powershell 模塊。 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"
結果是:
alert_limit customer_email
----------- --------------
150 user1@email1.com
12000 user2@email2.com
10000 user3@email3.com
我正在嘗試將個人 email 發送到每個 customer_email 並在正文中限制)如下:
$Parameters = @{
ToAddress = '$customer_email'
FromAddress = "notifications@system.com"
Subject = "Credits"
Body = "your credits are bellow" '$alert_limit'
但我努力爭取 select 個人條目。 謝謝
我已經做了。
ForEach($customer in $query) {
$alert_limit= $customer.alert_limit
$customer_email = $customer.customer_email
$Parameters = @{
ToAddress ="$customer_email"
FromAddress = "notifications@system.com"
Subject = "Credits"
Body = "your credits are below<br> $alert_limit"
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.