IT-Yogi

Flexibla lösningar!

Följ mig

twittergoogle_pluslinkedinby feather
You are here: Home / IT / Automatiskt maila användare vars certifikat håller på att gå ut.

Automatiskt maila användare vars certifikat håller på att gå ut.

October 7, 2013 by Lars Gustavsson Leave a Comment

Mail users whose certs expired
PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Script that mails users whos certificate is about to expire.
# Created by: Lars Gustavsson
# Version: 1.0
# Changelog: 1.0 Created
#
# Instructions:
# Change the varibles for days when the certificate expires, the certificate server to use and the certificate template to filter by.
# Make sure to set the execution policy to unrestricted with "set-execution policy unrestricted"
 
#Importes the PSPKI Module, it needs to be installed first, download from http://pspki.codeplex.com/releases/view/110129
import-module PSPKI
 
$Template = "SmartCard"
$CAServer = "caserver.domain.suffix"
#Days which to search for expired certificates in.
$Days = "14"
$MailFrom = "IT-Servicedesk@domain.suffix"
$SMTP = "smtp.domain.suffix"
$Subject = '"Your smartcard certificate is about to expire"'
 
$UserRcpts = Get-CertificationAuthority $CAServer | Get-IssuedRequest -Property CertificateTemplate,UPN -Filter "NotAfter -ge $(Get-Date)", "NotAfter -le $((Get-Date).AddDays($Days))","CertificateTemplate -eq $Template"
 
ForEach ($User in $UserRcpts) {
 
$MailRcpt = $User.UPN
$date = $MailRcpt.NotAfter
$MailBody = '"Your smartcard expires ' + $date + ', please contact IT-Servicedesk to renew! You need your smartcard to your computer."'
 
#Looks up the users email in Active Directory.
$Mail = Get-ADUser -filter {(UserPrincipalName -eq $MailRcpt)} -Properties Mail
 
#Checking that a mail was found before sending.
if ($Mail.Mail -ne $Null)
{
Write-host "Send-MailMessage -To" $Mail.Mail "-Body $MailBody -From $MailFrom -Subject $Subject -SmtpServer $SMTP"
}
}

 

Skriptet bygger på att du har modulen PSPKI installerad från http://pspki.codeplex.com/releases/view/110129

 

 

Intressant? Dela på:
twittergoogle_pluslinkedinby feather

Filed Under: IT, Skript

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Ämnen

  • Health
  • IT
    • Skript
    • Solutions (English)

Senast skrivet

  • Fitness, health and movement
  • Installera serverroller från xml del 2
  • Installera serverroller från xml
  • Quickly set new DNS servers on a certain subnet
  • Kerberos Constrained Delegation and Managed Service Accounts

Bloggegor

  • Fredrik Pålerud
  • Henrik Ericsson
  • Jimmy Andersson
  • Johan Arwidmark
  • Kim Hellman
  • Oscar Virot
  • Simon Wåhlin
  • Tobias Öien
  • Tomas Lepa

Arkiv

Recent Comments

  • Installera serverroller från xml del 2 | IT-Yogi on Automatiskt skapa websiter från CSV-fil
  • Installera serverroller från xml del 2 | IT-Yogi on Installera serverroller från xml
  • Remembers that casting variables is sticky | Tidbits of Information from Virot on Automatiskt skapa websiter från CSV-fil

Copyright © 2019 · BlogNews Theme on Genesis Framework · WordPress · Log in