[英]Sendgrid powershell report for multiple subusers
So i`m trying to export all blocks for a subuser account in sendgrid, for which i have the following code所以我正在尝试导出 sendgrid 中子用户帐户的所有块,为此我有以下代码
$headers = @{
'Authorization' = 'Bearer ' + $apiKey
'Content-Type' = 'application/json'
'on-behalf-of' = 'ACCOUNT-NAME'
}
Invoke-RestMethod -Method Get -Uri 'https://api.sendgrid.com/v3/suppression/blocks' -Headers $headers
Which works as expected, the thing is that I have around 30 subusers for which I need these details.这按预期工作,问题是我有大约 30 个子用户需要这些详细信息。
How can I do the foreach
loop so I can get the data for all of them?如何执行foreach
循环以便获取所有这些循环的数据?
Thanks:)谢谢:)
Simply replace the hardcoded account name with whatever variable name you choose for the foreach
loop variable, and the appropriate property name:只需将硬编码的帐户名称替换为您为foreach
循环变量选择的任何变量名称,以及适当的属性名称:
$users = Invoke-RestMethod -Method Get -Uri 'https://api.sendgrid.com/v3/subusers'
foreach($user in $users){
$headers = @{
'Authorization' = 'Bearer ' + $apiKey
'Content-Type' = 'application/json'
'on-behalf-of' = $user.username # here we grab the username from the current $user
}
Invoke-RestMethod -Method Get -Uri 'https://api.sendgrid.com/v3/suppression/blocks' -Headers $headers
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.