2017-01-30 6 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 ... 
    }