2017-01-30 2 views
0

タイトルには、私たちの組織内で証明書の更新を自動化しようとしています。今、これはすべてExcelスプレッドシートで追跡されます。今私はスクリプトが期限切れであることを私たちのチームに伝えています。私がしたいことは、期限切れの証明書を使って各チームに送信することです。私が持っているスクリプトは、現在、以下の通りです:CSVファイルの解析スクリプトを作成し、証明書更新担当者に電子メールを送信しようとしています

Import-Csv -path D:\Scripts\Get-ExpiringCertificates\Certificates.csv | 
    Where-Object {$_.Status -like "Expires*"} | 
    Export-Csv D:\Scripts\Get-ExpiringCertificates\ExpiringCerts.csv 
Send-MailMessage -From "[email protected]" -To [email protected] -Subject "Expiring Certs" -SmtpServer "mailint.edmc.edu" -Attachments D:\Scripts\Get-ExpiringCertificates\ExpiringCerts.csv -Body "Please see attachment for the list of Certificates Expiring within the next 90 days." 

私は、これはおそらく、各責任者のためのif文を持っている必要がありそう以上であることを知っています。

使用されているCSVの例:

CSV screenshot

答えて

1

代わりに責任がある当事者によってバックファイルグループに期限切れの証明書をインポートしたCSVデータをエクスポートするの、自分のメールアドレスを検索し、グループ化を送ります責任あるチームに情報を提供する。

Import-Csv -path D:\Scripts\Get-ExpiringCertificates\Certificates.csv | 
    Where-Object {$_.Status -like "Expires*"} | 
    Group-Object 'Responsible Party' | 
    ForEach-Object { 
     $responsibleParty = $_.Name 
     $recipient = ... # look up mail address for $responsibleParty 
     $data = $_.Group | ConvertTo-Csv -NoType 
     Send-MailMessage -To $recipient -Body $data ... 
    } 
関連する問題