%3CLINGO-SUB%20id%3D%22lingo-sub-1128609%22%20slang%3D%22en-US%22%3EPowershell%20CRL%20Copy%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1128609%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20TECHNET%20on%20May%2012%2C%202010%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThis%20script%20writes%20a%20Certification%20Authority's%20Certificate%20Revocation%20List%20to%20HTTP%20based%20CRL%20Distribution%20Points%20via%20a%20UNC%20path.%20It%20checks%20to%20make%20sure%20that%20the%20copy%20was%20successful%20and%20that%20the%20CDPs%20have%20not%20and%20are%20not%20about%20to%20expire.%20Alerts%2Fstatus%20messages%20are%20sent%20via%20SMTP%20and%20eventlog%20entries.%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%20%3CU%3E%20Performs%20the%20following%20steps%3A%20%3C%2FU%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EDetermines%20if%20the%20Active%20Directory%20Certificate%20Services%20are%20running%20on%20the%20system.%20In%20the%20case%20of%20a%20cluster%20make%20sure%20to%20set%20the%20%24Cluster%20variable%20to%20'%24TRUE'%3C%2FLI%3E%0A%3CLI%3EReads%20the%20CA's%20CRL%20from%20%25windir%25%5Csystem32%5Ccertsrv%5Ccertenroll%20(defined%20by%20%24crl_master_path%20%2B%20%24crl_name%20variables).%20I'll%20refer%20to%20this%20CRL%20as%20%22Master%20CRL.%22%3C%2FLI%3E%0A%3CLI%3EChecks%20the%20NextUpdate%20value%20of%20the%20Master%20CRL%20to%20make%20sure%20is%20has%20not%20expired.%20(Note%20that%20the%20Mono%20library%20adds%20hours%20to%20the%20NextUpdate%20and%20ThisUpdate%20values%2C%20control%20this%20time%20difference%20with%20the%20%24creep%20variable)%3C%2FLI%3E%0A%3CLI%3ECopy%20Master%20CRL%20to%20CDP%20UNC%20locations%20if%20Master%20CRL's%20ThisUpdate%20is%20greater%20than%20CDP%20CRLs'%20ThisUpdate%3C%2FLI%3E%0A%3CLI%3ECompare%20the%20hash%20values%20of%20the%20CRLs%20to%20make%20sure%20the%20copy%20was%20successful.%20If%20they%20do%20not%20match%20override%20the%20%24SMTP%20variable%20to%20send%20email%20alert%20message.%3C%2FLI%3E%0A%3CLI%3EWhen%20Master%20CRL's%20ThisUpdate%20is%20greater%20than%20NextCRLPublish%20and%20NextUpdate%20we%20want%20to%20be%20alerted%20when%20the%20Master%20CRL%20is%20approaching%20end%20of%20life.%20Use%20the%20%24threshold%20variable%20to%20define%20(in%20hours%2C%20.5%20%3D%2030%20minutes)%20how%20far%20from%20NextUpdate%20you%20want%20to%20receive%20warnings%20that%20the%20CRLs%20are%20soon%20to%20expire.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3E%20%3CU%3E%20Output%3A%20%3C%2FU%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ERun%20script%20initially%20as%20local%20administrator%20to%20register%20with%20the%20system's%20application%20eventlog%3C%2FLI%3E%0A%3CLI%3ESend%20SMTP%20message%20if%20%24STMP%20%3D%20True.%20Set%20variable%20section%20containing%20SMTP%20settings%20for%20your%20environment%3C%2FLI%3E%0A%3CLI%3ETo%20run%20this%20script%20with%20debug%20output%20set%20powershell%20%24DebugPreference%20%3D%20%22Continue%22%3C%2FLI%3E%0A%3CLI%3EThe%20'results'%20function%20is%20used%20to%20write%20to%20the%20eventlog%20and%20send%20SMTP%20messages.%20Event%20levels%20are%20controlled%20in%20the%20variable%20section.%20For%20example%20a%20failed%20CRL%20copy%20you%20want%20to%20make%20sure%20the%20eventlog%20show%20%22Error%22%20(%24EventHigh)%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3E%20%3CU%3E%20Requirements%3A%20%3C%2FU%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EWindows%20Powershell%20v2%20included%20in%20the%20Windows%20Management%20Framework%20%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F968929%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F968929%20%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EPowershell%20Community%20Extensions%20for%20the%20Get-Hash%20commandlet%20%3CA%20href%3D%22http%3A%2F%2Fpscx.codeplex.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fpscx.codeplex.com%20%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3EThis%20powershell%20script%20uses%20a%20third%20party%2C%20open%20source%20.Net%20reference%20called%20'Mono.'%20More%20information%20can%20be%20found%20at%20%3CA%20href%3D%22http%3A%2F%2Fwww.mono-project.com%2FMain_Page%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.mono-project.com%2FMain_Page%3C%2FA%3E%20(Note%3A%20the%20Mono%20assembly%20Mono.Security.x509.x509CRL%20adds%204%20hours%20to%20the%20.NextUpdate%2C%20.ThisUpdate%20and%20.IsCurrent%20function)%3C%2FLI%3E%0A%3CLI%3EDon't%20forget%20to%20set%20the%20powershell%20set-executionpolicy%3C%2FLI%3E%0A%3CLI%3ERun%20the%20script%20as%20a%20scheduled%20task%20every%2030%20minutes%3COL%3E%0A%3CLI%3EStart%20Task%20Scheduler%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3E%20%3CI%3E%20Create%20Basic%20Task%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3E%20%3CI%3E%20Daily%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESet%20%3CSTRONG%3E%20%3CI%3E%20Repeat%20task%20every%3A%2030%20minutes%20for%20the%20duration%20of%3A%20Indefinitely%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3E%20%3CI%3E%20Start%20a%20program%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESet%20%3CSTRONG%3E%20%3CI%3E%20Program%2Fscript%20%3D%20%25SystemRoot%25%5Csystem32%5CWindowsPowerShell%5Cv1.0%5Cpowershell.exe%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESet%20%3CSTRONG%3E%20%3CI%3E%20Argument%20%3D%20%3CFULL_PATH%3Ecrl_copy.ps1%3C%2FFULL_PATH%3E%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EWithin%20the%20Task%E2%80%99s%20Properties%20-%26gt%3B%20General%20tab%20select%20the%20following%20Security%20Options%3COL%3E%0A%3CLI%3ESelect%20%3CSTRONG%3E%20%3CI%3E%20Change%20User%20or%20Group%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3EAdd%20service%20account%20used%20to%20perform%20backups%2C%20make%20sure%20it%20has%20sufficient%20rights%20(remember%20to%20run%20the%20script%20as%20local%20administrator%20the%20first%20time%20to%20register%20with%20the%20eventlog)%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3E%20%3CI%3E%20Run%20whether%20user%20is%20logged%20on%20or%20not%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3ESelect%20%3CSTRONG%3E%20%3CI%3E%20Run%20with%20highest%20privileges%3C%2FI%3E%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3E%20%3CU%3E%20ToDos%3A%20%3C%2FU%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20any%20ideas%2C%20please%20share%20them.%20A%20couple%20of%20thoughts%20about%20future%20improvements%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EBind%20to%20an%20LDAP%20directory%20to%20retrieve%20CRL%20(e.g.%20ldap%3A%2F%2Ffpkia.gsa.gov%2FCommonPolicy%2FCommonPolicy(1).crl)%3C%2FLI%3E%0A%3CLI%3EUse%20multidimensional%20arrays%20to%20store%20CDP%20HTTP%20and%20UNC%20addresses%3C%2FLI%3E%0A%3CLI%3EImprove%20error%20handling%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSTRONG%3E%20%3CU%3E%20Variables%3A%20%3C%2FU%3E%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EMake%20sure%20to%20set%20for%20your%20environment%3C%2FP%3E%0A%3CTABLE%20border%3D%221%22%20cellspacing%3D%220%22%20cellpadding%3D%220%22%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24crl_master_path%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3ELocation%20where%20the%20CA%20writes%20the%20Master%20CRL%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24CRL_Name%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EName%20of%20the%20CRL%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24CDP1_UNC%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EUNC%20path%20to%20CDP1%20make%20sure%20the%20path%20ends%20with%20%E2%80%9C%5C%E2%80%9D%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24CDP2_UNC%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EUNC%20path%20to%20CDP2%20make%20sure%20the%20path%20ends%20with%20%E2%80%9C%5C%E2%80%9D%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24CDP1_HTTP%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EHTTP%20path%20to%20CDP1%20make%20sure%20the%20path%20ends%20with%20%E2%80%9C%2F%E2%80%9D%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24CDP2_HTTP%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EHTTP%20path%20to%20CDP2%20make%20sure%20the%20path%20ends%20with%20%E2%80%9C%2F%E2%80%9D%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24SMTP%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EBoolean%20value%20to%20determine%20if%20SMTP%20message%20is%20sent%20via%20the%20%E2%80%98results%E2%80%99%20function%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24SmtpServer%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EHostname%20(name%2C%20FQDN%20or%20IP)%20of%20SMTP%20server%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24From%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3EFrom%20address%20of%20SMTP%20based%20message%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24To%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3ERecipients%20of%20SMTP%20message%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24Title%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3ESubject%20of%20SMTP%20message%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24CRL_Evt_Source%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3ESource%20field%20of%20Application%20eventlog%20entry%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24threshold%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3E%23%20of%20hours%20before%20the%20reaching%20the%20Master%20CRL%E2%80%99s%20NextUpdate%20time%20(early%20warning)%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24creep%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3E%23%20of%20hours%20that%20the%20Mono%20library%20adds%20to%20NextUpdate%20and%20ThisUpdate%20values%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22319%22%20valign%3D%22top%22%3E%3CP%3E%24Cluster%3C%2FP%3E%0A%3C%2FTD%3E%0A%3CTD%20width%3D%22646%22%20valign%3D%22top%22%3E%3CP%3ESet%20to%20%E2%80%98true%E2%80%99%20if%20your%20Certification%20Authority%20is%20clustered%3C%2FP%3E%0A%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20644px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F167149i376DEA02CD38B08E%2Fimage-dimensions%2F644x478%3Fv%3D1.0%22%20width%3D%22644%22%20height%3D%22478%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CBLOCKQUOTE%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Title%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20CRLCopy.ps1%20%3CBR%20%2F%3E%23%20Date%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%204%2F28%2F2010%20%3CBR%20%2F%3E%23%20Author%3A%20Paul%20Fox%20(MCS)%20%3CBR%20%2F%3E%23%20Copyright%20Microsoft%20Corporation%20%402010%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Description%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20This%20script%20writes%20a%20Certification%20Authority's%20Certificate%20Revocation%20List%20to%20HTTP%20based%20CRL%20Distribution%20Points%20via%20a%20UNC%20path.%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Performs%20the%20following%20steps%3A%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%201)%20Determines%20if%20the%20Active%20Directory%20Certificate%20Services%20are%20running%20on%20the%20system.%20In%20the%20case%20of%20a%20cluster%20make%20sure%20to%20set%20the%20%24Cluster%20variable%20to%20'%24TRUE'%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%202)%20Reads%20the%20CA's%20CRL%20from%20%25windir%25%5Csystem32%5Ccertsrv%5Ccertenroll%20(defined%20by%20%24crl_master_path%20%2B%20%24crl_name%20variables).%20I'll%20refer%20to%20this%20CRL%20as%20%22Master%20CRL.%22%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%203)%20Checks%20the%20NextUpdate%20value%20of%20the%20Master%20CRL%20to%20make%20sure%20is%20has%20not%20expired.%20(Note%20that%20the%20Mono%20library%20adds%20hours%20to%20the%20NextUpdate%20and%20EffectiveDate%20values%2C%20control%20this%20time%20difference%20with%20the%20%24creep%20variable)%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%204)%20Copy%20Master%20CRL%20to%20CDP%20UNC%20locations%20if%20Master%20CRL's%20ThisUpdate%20is%20greater%20than%20CDP%20CRLs'%20ThisUpdate%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%205)%20Compare%20the%20hash%20values%20of%20the%20CRLs%20to%20make%20sure%20the%20copy%20was%20successful.%20If%20they%20do%20not%20match%20override%20the%20%24SMTP%20variable%20to%20send%20email%20alert%20message.%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%206)%20When%20Master%20CRL's%20ThisUpdate%20is%20greater%20than%20NextCRLPublish%20and%20NextUpdate%20we%20want%20to%20be%20alerted%20when%20the%20Master%20CRL%20is%20approaching%20end%20of%20life.%20Use%20the%20%24threshold%20variable%20to%20define%20(in%20hours)%20how%20far%20from%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20NextUpdate%20you%20want%20to%20receive%20warnings%20that%20the%20CRLs%20are%20soon%20to%20expire.%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Output%3A%201)%20Run%20script%20initially%20as%20local%20administrator%20to%20register%20with%20the%20system's%20application%20eventlog%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%202)%20Send%20SMTP%20message%20if%20%24STMP%20%3D%20True.%20Set%20variable%20section%20containing%20SMTP%20settings%20for%20your%20environment%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%203)%20To%20run%20this%20script%20with%20debug%20output%20set%20powershell%20%24DebugPreference%20%3D%20%22Continue%22%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%204)%20The%20'results'%20function%20is%20used%20to%20write%20to%20the%20eventlog%20and%20send%20SMTP%20messages.%20Event%20levels%20are%20controlled%20in%20the%20variable%20section.%20For%20example%20a%20failed%20CRL%20copy%20you%20want%20to%20make%20sure%20the%20eventlog%20show%20%22Error%22%20(%24EventHigh)%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Requirements%3A%201)%20Windows%20Powershell%20v2%20included%20in%20the%20Windows%20Management%20Framework%20%3CA%20href%3D%22http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F968929%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fsupport.microsoft.com%2Fkb%2F968929%20%3C%2FA%3E%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%202)Powershell%20Community%20Extensions%20for%20the%20Get-Hash%20commandlet%20%3CA%20href%3D%22http%3A%2F%2Fpscx.codeplex.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fpscx.codeplex.com%20%3C%2FA%3E%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%203)%20This%20powershell%20script%20uses%20a%20third%20party%2C%20open%20source%20.Net%20reference%20called%20'Mono'%26nbsp%3B%26nbsp%3B%26nbsp%3B%20More%20information%20can%20be%20found%20at%20%3CA%20href%3D%22http%3A%2F%2Fwww.mono-project.com%2FMain_Page%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fwww.mono-project.com%2FMain_Page%20%3C%2FA%3E%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Note%3A%20the%20Mono%20assembly%20Mono.Security.x509.x509CRL%20adds%204%20hours%20to%20the%20.NextUpdate%2C%20.ThisUpdate%20and%20.IsCurrent%20function%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%204)%20Don't%20forget%20to%20set%20the%20powershell%20set-executionpolicy%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20ToDos%3A%20Bind%20to%20an%20LDAP%20directory%20to%20retrieve%20CRL%20(e.g.%20ldap%3A%2F%2Ffpkia.gsa.gov%2FCommonPolicy%2FCommonPolicy(1).crl)%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Use%20multidimensional%20arrays%20to%20store%20CDP%20HTTP%20and%20UNC%20addresses%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Debug%3A%20To%20run%20this%20script%20with%20debug%20output%20set%20powershell%20%24DebugPreference%20%3D%20%22Continue%22%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Function%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Results%20%3CBR%20%2F%3E%23%20Description%3A%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Writes%20the%20%24evt_string%20to%20the%20Application%20eventlog%20and%20sends%20%3CBR%20%2F%3E%23%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20SMTP%20message%20to%20recipients%20if%20%24SMTP%20%3D%20%5Bbool%5D%24true%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Efunction%20results(%5Bstring%5D%24evt_string%2C%20%5Bint%5D%24level%20%2C%5Bbool%5D%24sendsmtp)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22********%20Inside%20results%20function%20********%22%20%3CBR%20%2F%3Ewrite-debug%20%22SMTP%20%3D%20%24sendsmtp%22%20%3CBR%20%2F%3Ewrite-debug%20%22Evtstring%20%3D%20%24evt_string%22%20%3CBR%20%2F%3Ewrite-debug%20%22Level%3A%20%24level%22%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23if%20eventlog%20does%20not%20exist%20create%20it%20(must%20run%20script%20as%20local%20administrator%20once%20to%20create)%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Eif(!%5Bsystem.diagnostics.eventlog%5D%3A%3AsourceExists(%24CRL_Evt_Source))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24evtlog%20%3D%20%5Bsystem.diagnostics.eventlog%5D%3A%3ACreateEventSource(%24CRL_Evt_Source%2C%22Application%22)%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20set%20eventlog%20object%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24evtlog%20%3D%20new-object%20system.diagnostics.eventlog(%22application%22%2C%22.%22)%20%3CBR%20%2F%3E%24evtlog.source%20%3D%20%24CRL_Evt_Source%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20write%20to%20eventlog%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24evtlog.writeEntry(%24evt_string%2C%20%24level%2C%20%24EventID)%3C%2FP%3E%0A%3CP%3Eif(%24sendsmtp)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24SmtpClient%20%3D%20new-object%20system.net.mail.smtpClient%20%3CBR%20%2F%3E%24SmtpClient.host%20%3D%20%24SmtpServer%20%3CBR%20%2F%3E%24Body%20%3D%20%24evt_string%20%3CBR%20%2F%3E%24SmtpClient.Send(%24from%2C%24to%2C%24title%2C%24Body)%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Main%20program%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Add%20Mono%20.Net%20References%20%3CBR%20%2F%3E%23%20If%20running%20on%20an%20x64%20system%20make%20sure%20the%20path%20is%20correct%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3EAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%20(x86)%5CMono-2.6.4%5Clib%5Cmono%5C2.0%5CMono.Security.dll%22%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Variables%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24crl_master_path%20%3D%20%22c%3A%5Cwindows%5Csystem32%5Ccertsrv%5Ccertenroll%5C%22%20%3CBR%20%2F%3E%24CRL_Name%20%3D%20%22master.crl%22%20%3CBR%20%2F%3E%24CDP1_UNC%20%3D%20%22%5C%5Ccdp1%5Ccdp1%5C%22%20%3CBR%20%2F%3E%24CDP2_UNC%20%3D%20%22%5C%5Ccdp2%5Ccdp2%5C%22%20%3CBR%20%2F%3E%24CDP1_HTTP%20%3D%20%22%20%3CA%20href%3D%22http%3A%2F%2Fkeys1.your.domain%2F%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fkeys1.your.domain%2F%22%20%3C%2FA%3E%20%3CBR%20%2F%3E%24CDP2_HTTP%20%3D%20%22%20%3CA%20href%3D%22http%3A%2F%2Fkeys2.your.domain%2F%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fkeys2.your.domain%2F%22%20%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%24SMTP%20%3D%20%5Bbool%5D%24false%20%3CBR%20%2F%3E%24SmtpServer%20%3D%20%22your.mx.mail.server%22%20%3CBR%20%2F%3E%24From%20%3D%20%22crlcopy%40your.domain%22%20%3CBR%20%2F%3E%24To%20%3D%20%22CAAdmins%40your.domain%22%20%3CBR%20%2F%3E%24Title%20%3D%20%22CRL%20Copy%20Process%20Results%22%3C%2FP%3E%0A%3CP%3E%24CRL_Evt_Source%20%3D%20%22CRL%20Copy%20Process%22%20%3CBR%20%2F%3E%24EventID%20%3D%20%225000%22%20%3CBR%20%2F%3E%24EventHigh%20%3D%20%221%22%20%3CBR%20%2F%3E%24EventWarning%20%3D%20%222%22%20%3CBR%20%2F%3E%24EventInformation%20%3D%20%224%22%3C%2FP%3E%0A%3CP%3E%24newline%20%3D%20%5BSystem.Environment%5D%3A%3ANewLine%20%3CBR%20%2F%3E%24time%20%3D%20Get-Date%20%3CBR%20%2F%3E%24threshold%20%3D%201%20%3CBR%20%2F%3E%24creep%20%3D%20-4%20%3CBR%20%2F%3E%24Cluster%20%3D%26nbsp%3B%20%5Bbool%5D%24false%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Is%20certsrv%20running%3F%20Is%20it%20a%20clustered%20CA%3F%20%3CBR%20%2F%3E%23%20If%20clustered%20it%20is%20not%20running%20don't%20send%20an%20SMTP%20message%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24service%20%3D%20get-service%20%7C%20where-Object%20%7B%24_.name%20-eq%20%22certsvc%22%7D%3C%2FP%3E%0A%3CP%3Eif%20(!(%24service.Status%20-eq%20%22Running%22))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Eif(%24Cluster)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24evt_string%20%3D%20%22Active%20Directory%20Certificate%20Services%20is%20not%20running%20on%20this%20node%20of%20the%20cluster.%20Exiting%20program.%22%20%3CBR%20%2F%3Ewrite-debug%20%22ADCS%20is%20not%20running.%20This%20is%20a%20clustered%20node.%20Exiting%22%20%3CBR%20%2F%3Eresults%20%24evt_string%20%24EventInformation%20%24SMTP%20%3CBR%20%2F%3Eexit%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24evt_string%20%3D%20%22****%20IMPORTANT%20****%20IMPORTANT%20****%20IMPORTANT%20****%22%20%2B%26nbsp%3B%20%24newline%20%2B%20%22Certsvc%20status%20is%3A%20%22%20%2B%20%24service.status%20%2B%20%24newline%20%3CBR%20%2F%3Ewrite-debug%20%22ADCS%20is%20not%20running%20and%20not%20a%20clustered%20node.%20Not%20good.%22%20%3CBR%20%2F%3Eresults%20%24evt_string%20%24EventHigh%20%24SMTP%20%3CBR%20%2F%3Eexit%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22Certsvc%20is%20running.%20Continue.%22%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Pull%20CRLs%20from%20Master%20and%20HTTP%20CDP%20locations%20%3CBR%20%2F%3E%23%20Not%20going%20to%20bother%20with%20Active%20Directory%20since%20this%20%3CBR%20%2F%3E%23%20is%20probably%20a%20Windows%20Enterprise%20CA%20(todo)%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24CRL_Master%20%3D%20%5BMono.Security.X509.X509Crl%5D%3A%3ACreateFromFile(%24crl_master_path%20%2B%20%24CRL_Name)%20%3CBR%20%2F%3E%24web_client%20%3D%20New-Object%20System.Net.WebClient%20%3CBR%20%2F%3E%24CDP1_CRL%20%3D%20%5BMono.Security.X509.X509Crl%5D%24web_client.DownloadData(%24CDP1_HTTP%20%2B%20%24CRL_Name)%20%3CBR%20%2F%3E%24CDP2_CRL%20%3D%20%5BMono.Security.X509.X509Crl%5D%24web_client.DownloadData(%24CDP2_HTTP%20%2B%20%24CRL_Name)%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Debug%20section%20to%20give%20you%20the%20time%2Fdates%20of%20the%20CRLs%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Eif(%24debugpreference%20-eq%20%22continue%22)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%24newline%20%3CBR%20%2F%3Ewrite-debug%20%22Master%20CRL%20Values%22%20%3CBR%20%2F%3E%24debug_out%20%3D%20%24CRL_Master.ThisUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22Master%20ThisUpdate%20%24debug_out%22%20%3CBR%20%2F%3E%24debug_out%20%3D%20%24CDP1_CRL.ThisUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22CDP1_CRL%20ThisUpdate%3A%20%24debug_out%22%20%3CBR%20%2F%3E%24debug_out%20%3D%20%24CDP2_CRL.ThisUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22CDP2_CRL%20ThisUpdate%3A%20%24debug_out%22%20%3CBR%20%2F%3E%24debug_out%20%3D%20%24CRL_Master.NextUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22Master%20NextUpdate%3A%20%24debug_out%22%20%3CBR%20%2F%3E%24debug_out%20%3D%20%24CDP1_CRL.NextUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22CDP1_CRL%20NextUpdate%3A%20%24debug_out%22%20%3CBR%20%2F%3E%24debug_out%20%3D%20%24CDP2_CRL.NextUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22CDP2_CRL%20NextUpdate%3A%20%24debug_out%22%20%3CBR%20%2F%3Ewrite-debug%20%24newline%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Determine%20the%20status%20of%20the%20master%20CRL%20%3CBR%20%2F%3E%23%20Master%20and%20CDP%20CRLs%20have%20the%20same%20EffectiveDate%20(Mono%20%3D%20ThisUpdate)%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Eif(%24CRL_Master.NextUpdate.AddHours(%24creep)%20-gt%20%24time)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%23%20This%20is%20healthy%20Master%20CRL%20%3CBR%20%2F%3Ewrite-debug%20%22Master%20CRL%20EffectiveDate%3A%20%22%20%3CBR%20%2F%3Ewrite-debug%20%24CRL_Master.ThisUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Ewrite-debug%20%22Time%20now%20is%3A%20%22%20%3CBR%20%2F%3Ewrite-debug%20%24time%20%3CBR%20%2F%3Ewrite-debug%20%24newline%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%23%20Everything%20has%20gone%20stale%2C%20not%20good.%20Alert.%20%3CBR%20%2F%3Ewrite-debug%20%22Master%20CRL%20has%20gone%20stale%22%20%3CBR%20%2F%3E%24evt_string%20%3D%20%22****%20IMPORTANT%20****%20IMPORTANT%20****%20IMPORTANT%20****%22%20%2B%20%24newline%20%2B%20%22Master%20CRL%3A%20%22%20%2B%20%24CRL_Name%20%2B%20%22%20has%20an%20EffectiveDate%20of%3A%20%22%20%2B%20%24CRL_Master.ThisUpdate.AddHours(%24creep)%20%2B%20%22%20and%20an%20NextUpdate%20of%3A%20%22%20%2B%20%24CRL_Master.NextUpdate.AddHours(%24creep)%20%2B%20%24newline%20%2B%20%22Certsvc%20status%20is%3A%20%22%20%2B%20%24service.status%20%3CBR%20%2F%3Eresults%20%24evt_string%20%24EventHigh%20%24SMTP%20%3CBR%20%2F%3Eexit%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Determine%20what%20the%20status%20of%20the%20CDPs%20%3CBR%20%2F%3E%23%20Does%20the%20Master%20and%20the%20CDP%20CRLs%20match%20up%3F%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Eif%20((%24CRL_Master.ThisUpdate%20-eq%20%24CDP1_CRL.ThisUpdate)%20-and%20(%24CRL_Master.ThisUpdate%20-eq%20%24CDP2_CRL.ThisUpdate))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22All%20CRLs%20EffectiveDates%20match%22%20%3CBR%20%2F%3Ewrite-debug%20%24CRL_Master.ThisUpdate%20%3CBR%20%2F%3Ewrite-debug%20%24CDP1_CRL.ThisUpdate%20%3CBR%20%2F%3Ewrite-debug%20%24CDP2_CRL.ThisUpdate%20%3CBR%20%2F%3Ewrite-debug%20%24newline%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20New%20Master%20CRL%2C%20Update%20CDP%20CRLs%20if%20or%20or%20both%20are%20old%20%3CBR%20%2F%3E%23%20would%20be%20nice%20to%20use%20the%20'CRL%20Number'%20%3CBR%20%2F%3E%23%20Compare%20the%20hash%20values%20of%20the%20Master%20CRL%20and%20CDP%20CRLs%20%3CBR%20%2F%3E%23%20after%20the%20copy%20command%20to%20make%20sure%20the%20copy%20completed%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Eelseif%20((%24CRL_Master.ThisUpdate%20-gt%20%24CDP1_CRL.ThisUpdate)%20-or%20(%24CRL_Master.ThisUpdate%20-gt%20%24CDP2_CRL.ThisUpdate))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%23%20There%20is%20a%20new%20master%20CRL%2C%20copy%20to%20CDPs%20%3CBR%20%2F%3Ewrite-debug%20%22New%20master%20crl.%20Copy%20out%20to%20CDPs%22%20%3CBR%20%2F%3E%24source%20%3D%20Get-Item%20%24crl_master_path%24CRL_Name%20%3CBR%20%2F%3ECopy-Item%20%24source%20%24CDP1_UNC%24CRL_Name%20%3CBR%20%2F%3ECopy-Item%20%24source%20%24CDP2_UNC%24CRL_Name%20%3CBR%20%2F%3E%23%20Compare%20the%20hash%20values%20of%20the%20master%20CRL%20to%20the%20CDP%20CRL%20%3CBR%20%2F%3E%23%20If%20they%20do%20not%20equal%20alert%20via%20SMTP%20by%20setting%20the%20%24SMTP%20boolian%20value%20to%20'%24true'%20%3CBR%20%2F%3E%24master_hash%20%3D%20get-hash%20%24source%20%3CBR%20%2F%3E%24cdp1_hash%20%3D%20get-hash%20%24CDP1_UNC%24CRL_Name%20%3CBR%20%2F%3E%24cdp2_hash%20%3D%20get-hash%20%24CDP2_UNC%24CRL_Name%20%3CBR%20%2F%3Eif((%24master_hash.HashString%20-ne%20%24cdp1_hash.HashString)%20-or%20(%24master_hash.HashString%20-ne%20%24cdp2_hash.HashString))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24evt_string%20%3D%20%22CRL%20copy%20to%20CDP%20location%20failed%3A%22%20%2B%24newline%20%2B%22Master%20CRL%20Hash%3A%20%22%20%2B%24master_hash.HashString%20%2B%24newline%20%2B%20%22CPD1%26nbsp%3B%20Hash%3A%22%20%2B%24cdp1_hash.HashString%20%2B%24newline%20%2B%20%22CDP2%20Hash%3A%22%20%2B%24cdp2_hash.HashString%20%2B%24newline%20%3CBR%20%2F%3E%23%20Make%20sure%20the%20email%20alert%20goes%20out.%20Override%20the%20%24SMTP%20variable%20%3CBR%20%2F%3Ewrite-debug%20%24newline%20%3CBR%20%2F%3Ewrite-debug%20%22CRLs%20copied%20to%20CDPs%20hash%20values%20do%20not%20match%20Master%20CRL%20Hash%22%20%3CBR%20%2F%3Ewrite-debug%20%22Master%20CRL%20Hash%20value%22%20%3CBR%20%2F%3Ewrite-debug%20%24master_hash.HashString%20%3CBR%20%2F%3Ewrite-debug%20%22CDP1%20CRL%20Hash%20value%22%20%3CBR%20%2F%3Ewrite-debug%20%24cdp1_hash.HashString%20%3CBR%20%2F%3Ewrite-debug%20%22CDP2%20CRL%20Hash%20value%22%20%3CBR%20%2F%3Ewrite-debug%20%24cdp2_hash.HashString%20%3CBR%20%2F%3E%24SMTP%20%3D%20%5Bbool%5D%24true%20%3CBR%20%2F%3Eresults%20%24evt_string%20%24EventHigh%20%24SMTP%20%3CBR%20%2F%3Eexit%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24evt_string%20%3D%20%22New%20Master%20CRL%20published%20to%20CDPs.%20%22%20%2B%20%24CRL_Name%20%2B%20%22%20has%20an%20EffectiveDate%20of%3A%20%22%20%2B%20%24CRL_Master.ThisUpdate.AddHours(%24creep)%20%2B%20%22%20and%20an%20NextUpdate%20of%3A%20%22%20%2B%20%24CRL_Master.NextUpdate.AddHours(%24creep)%20%3CBR%20%2F%3Eresults%20%24evt_string%20%24EventInformation%20%24SMTP%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22logic%20bomb%2C%20can't%20determine%20where%20the%20Master%20CRL%20is%20in%20relationship%20to%20the%20CDP%20CRLs%22%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%20Master%20CRL%E2%80%99s%20ThisUpdate%20time%20is%20in%20between%20the%20NextCRLPublish%20time%20and%20NextUpdate.%20%3CBR%20%2F%3E%23%20Note%20Mono%20does%20not%20have%20a%20method%20to%20read%20'NextCRLPublish'%20%3CBR%20%2F%3E%23%20The%20CA%20Operator%20can%20define%20the%20'%24threshold'%20at%20which%20that%20want%20to%20start%20receiving%20alerts%20%3CBR%20%2F%3E%23%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3Eif%20((%24CRL_Master.NextUpdate.AddHours(%24creep)%20-gt%20%24time)%20-and%20(%24CRL_Master.ThisUpdate.AddHours(%24creep)%20-lt%20%24time))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22checking%20threshold%22%20%3CBR%20%2F%3E%23%20Is%20the%20Master%20CRL%20NextUpdate%20within%20the%20defined%20alert%20threshold%3F%20%3CBR%20%2F%3Eif(%24CRL_Master.NextUpdate.AddHours(-(%24threshold%20-%20%24creep))%20-lt%20%24time)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22*****%20WARNING%20******%20Master%20CRL%20NextUpdate%20has%20a%20life%20less%20than%20threshold.%22%20%3CBR%20%2F%3Ewrite-debug%20%24CRL_Master.NextUpdate.AddHours(-(%24threshold%20-%20%24creep))%20%3CBR%20%2F%3E%24evt_string%20%3D%20%22*****%20WARNING%20******%20Master%20CRL%20NextUpdate%20has%20a%20life%20less%20than%20threshold%20of%3A%20%22%20%2B%20%24threshold%20%2B%20%22%20hour(s)%22%20%2B%20%24newline%20%2B%20%22Master%20CRLs%20NextUpdate%20is%3A%20%22%20%2B%20%24CRL_Master.NextUpdate.AddHours(%24creep)%20%2B%20%24newline%20%2B%22Certsvc%20service%20is%3A%20%22%20%2B%20%24service.Status%20%3CBR%20%2F%3Eresults%20%24evt_string%20%24EventWarning%20%24SMTP%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22Within%20the%20Master%20CRLs%20NextCRLPublish%20and%20NextUpdate%20period.%20Within%20threshold%20period.%22%20%3CBR%20%2F%3Ewrite-debug%20%24CRL_Master.NextUpdate.AddHours(-(%24threshold%20-%20%24creep))%20%3CBR%20%2F%3E%23%20Uncomment%20the%20following%20if%20you%20want%20notification%20on%20the%20CRLs%20%3CBR%20%2F%3E%23%24evt_string%20%3D%20%22Within%20the%20Master%20CRLs%20NextCRLPublish%20and%20NextUpdate%20period.%20Alerts%20will%20be%20send%20at%20%22%20%2B%20%24threshold%20%2B%20%22%20hour(s)%20before%20NextUpdate%20period%20is%20reached.%22%20%3CBR%20%2F%3E%23results%20%24evt_string%20%24EventInformation%20%24SMTP%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Ewrite-debug%20%22logic%20bomb%2C%20can't%20determine%20where%20we%20are%20in%20the%20threshold%22%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3C%2FBLOCKQUOTE%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1128609%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20TECHNET%20on%20May%2012%2C%202010%20This%20script%20writes%20a%20Certification%20Authority's%20Certificate%20Revocation%20List%20to%20HTTP%20based%20CRL%20Distribution%20Points%20via%20a%20UNC%20path.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1128609%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ECarstenKinder%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on TECHNET on May 12, 2010

This script writes a Certification Authority's Certificate Revocation List to HTTP based CRL Distribution Points via a UNC path. It checks to make sure that the copy was successful and that the CDPs have not and are not about to expire. Alerts/status messages are sent via SMTP and eventlog entries.

Performs the following steps:

  1. Determines if the Active Directory Certificate Services are running on the system. In the case of a cluster make sure to set the $Cluster variable to '$TRUE'
  2. Reads the CA's CRL from %windir%\system32\certsrv\certenroll (defined by $crl_master_path + $crl_name variables). I'll refer to this CRL as "Master CRL."
  3. Checks the NextUpdate value of the Master CRL to make sure is has not expired. (Note that the Mono library adds hours to the NextUpdate and ThisUpdate values, control this time difference with the $creep variable)
  4. Copy Master CRL to CDP UNC locations if Master CRL's ThisUpdate is greater than CDP CRLs' ThisUpdate
  5. Compare the hash values of the CRLs to make sure the copy was successful. If they do not match override the $SMTP variable to send email alert message.
  6. When Master CRL's ThisUpdate is greater than NextCRLPublish and NextUpdate we want to be alerted when the Master CRL is approaching end of life. Use the $threshold variable to define (in hours, .5 = 30 minutes) how far from NextUpdate you want to receive warnings that the CRLs are soon to expire.

Output:

  1. Run script initially as local administrator to register with the system's application eventlog
  2. Send SMTP message if $STMP = True. Set variable section containing SMTP settings for your environment
  3. To run this script with debug output set powershell $DebugPreference = "Continue"
  4. The 'results' function is used to write to the eventlog and send SMTP messages. Event levels are controlled in the variable section. For example a failed CRL copy you want to make sure the eventlog show "Error" ($EventHigh)

Requirements:

  1. Windows Powershell v2 included in the Windows Management Framework http://support.microsoft.com/kb/968929
  2. Powershell Community Extensions for the Get-Hash commandlet http://pscx.codeplex.com
  3. This powershell script uses a third party, open source .Net reference called 'Mono.' More information can be found at http://www.mono-project.com/Main_Page (Note: the Mono assembly Mono.Security.x509.x509CRL adds 4 hours to the .NextUpdate, .ThisUpdate and .IsCurrent function)
  4. Don't forget to set the powershell set-executionpolicy
  5. Run the script as a scheduled task every 30 minutes
    1. Start Task Scheduler
    2. Select Create Basic Task
    3. Select Daily
    4. Set Repeat task every: 30 minutes for the duration of: Indefinitely
    5. Select Start a program
    6. Set Program/script = %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
    7. Set Argument = <full_path>crl_copy.ps1
    8. Within the Task’s Properties -> General tab select the following Security Options
      1. Select Change User or Group
      2. Add service account used to perform backups, make sure it has sufficient rights (remember to run the script as local administrator the first time to register with the eventlog)
      3. Select Run whether user is logged on or not
      4. Select Run with highest privileges

ToDos:

If you have any ideas, please share them. A couple of thoughts about future improvements:

  1. Bind to an LDAP directory to retrieve CRL (e.g. ldap://fpkia.gsa.gov/CommonPolicy/CommonPolicy(1).crl)
  2. Use multidimensional arrays to store CDP HTTP and UNC addresses
  3. Improve error handling

Variables:

Make sure to set for your environment

$crl_master_path

Location where the CA writes the Master CRL

$CRL_Name

Name of the CRL

$CDP1_UNC

UNC path to CDP1 make sure the path ends with “\”

$CDP2_UNC

UNC path to CDP2 make sure the path ends with “\”

$CDP1_HTTP

HTTP path to CDP1 make sure the path ends with “/”

$CDP2_HTTP

HTTP path to CDP2 make sure the path ends with “/”

$SMTP

Boolean value to determine if SMTP message is sent via the ‘results’ function

$SmtpServer

Hostname (name, FQDN or IP) of SMTP server

$From

From address of SMTP based message

$To

Recipients of SMTP message

$Title

Subject of SMTP message

$CRL_Evt_Source

Source field of Application eventlog entry

$threshold

# of hours before the reaching the Master CRL’s NextUpdate time (early warning)

$creep

# of hours that the Mono library adds to NextUpdate and ThisUpdate values

$Cluster

Set to ‘true’ if your Certification Authority is clustered

 

################################################
#
# Title:     CRLCopy.ps1
# Date:     4/28/2010
# Author: Paul Fox (MCS)
# Copyright Microsoft Corporation @2010
#
# Description:     This script writes a Certification Authority's Certificate Revocation List to HTTP based CRL Distribution Points via a UNC path.
#               Performs the following steps:
#                 1) Determines if the Active Directory Certificate Services are running on the system. In the case of a cluster make sure to set the $Cluster variable to '$TRUE'
#                 2) Reads the CA's CRL from %windir%\system32\certsrv\certenroll (defined by $crl_master_path + $crl_name variables). I'll refer to this CRL as "Master CRL."
#                 3) Checks the NextUpdate value of the Master CRL to make sure is has not expired. (Note that the Mono library adds hours to the NextUpdate and EffectiveDate values, control this time difference with the $creep variable)
#                 4) Copy Master CRL to CDP UNC locations if Master CRL's ThisUpdate is greater than CDP CRLs' ThisUpdate
#                 5) Compare the hash values of the CRLs to make sure the copy was successful. If they do not match override the $SMTP variable to send email alert message.
#                 6) When Master CRL's ThisUpdate is greater than NextCRLPublish and NextUpdate we want to be alerted when the Master CRL is approaching end of life. Use the $threshold variable to define (in hours) how far from
#                    NextUpdate you want to receive warnings that the CRLs are soon to expire.
#
# Output: 1) Run script initially as local administrator to register with the system's application eventlog
#         2) Send SMTP message if $STMP = True. Set variable section containing SMTP settings for your environment
#         3) To run this script with debug output set powershell $DebugPreference = "Continue"
#         4) The 'results' function is used to write to the eventlog and send SMTP messages. Event levels are controlled in the variable section. For example a failed CRL copy you want to make sure the eventlog show "Error" ($EventHigh)
#
# Requirements: 1) Windows Powershell v2 included in the Windows Management Framework http://support.microsoft.com/kb/968929
#                 2)Powershell Community Extensions for the Get-Hash commandlet http://pscx.codeplex.com
#                 3) This powershell script uses a third party, open source .Net reference called 'Mono'    More information can be found at http://www.mono-project.com/Main_Page
#                             Note: the Mono assembly Mono.Security.x509.x509CRL adds 4 hours to the .NextUpdate, .ThisUpdate and .IsCurrent function
#                         4) Don't forget to set the powershell set-executionpolicy
#
# ToDos: Bind to an LDAP directory to retrieve CRL (e.g. ldap://fpkia.gsa.gov/CommonPolicy/CommonPolicy(1).crl)
#        Use multidimensional arrays to store CDP HTTP and UNC addresses
#
# Debug: To run this script with debug output set powershell $DebugPreference = "Continue"
#
################################################

################################################
#
# Function:     Results
# Description:    Writes the $evt_string to the Application eventlog and sends
#                SMTP message to recipients if $SMTP = [bool]$true
#
#
################################################
function results([string]$evt_string, [int]$level ,[bool]$sendsmtp)
{
write-debug "******** Inside results function ********"
write-debug "SMTP = $sendsmtp"
write-debug "Evtstring = $evt_string"
write-debug "Level: $level"
###############
#if eventlog does not exist create it (must run script as local administrator once to create)
###############
if(![system.diagnostics.eventlog]::sourceExists($CRL_Evt_Source))
{
$evtlog = [system.diagnostics.eventlog]::CreateEventSource($CRL_Evt_Source,"Application")
}

###############
# set eventlog object
###############
$evtlog = new-object system.diagnostics.eventlog("application",".")
$evtlog.source = $CRL_Evt_Source

###############
# write to eventlog
###############
$evtlog.writeEntry($evt_string, $level, $EventID)

if($sendsmtp)
{
$SmtpClient = new-object system.net.mail.smtpClient
$SmtpClient.host = $SmtpServer
$Body = $evt_string
$SmtpClient.Send($from,$to,$title,$Body)
}
}

################################################
#
# Main program
#
################################################

################################################
#
# Add Mono .Net References
# If running on an x64 system make sure the path is correct
#
################################################
Add-Type -Path "C:\Program Files (x86)\Mono-2.6.4\lib\mono\2.0\Mono.Security.dll"

################################################
#
# Variables
#
################################################
$crl_master_path = "c:\windows\system32\certsrv\certenroll\"
$CRL_Name = "master.crl"
$CDP1_UNC = "\\cdp1\cdp1\"
$CDP2_UNC = "\\cdp2\cdp2\"
$CDP1_HTTP = " http://keys1.your.domain/"
$CDP2_HTTP = " http://keys2.your.domain/"

$SMTP = [bool]$false
$SmtpServer = "your.mx.mail.server"
$From = "crlcopy@your.domain"
$To = "CAAdmins@your.domain"
$Title = "CRL Copy Process Results"

$CRL_Evt_Source = "CRL Copy Process"
$EventID = "5000"
$EventHigh = "1"
$EventWarning = "2"
$EventInformation = "4"

$newline = [System.Environment]::NewLine
$time = Get-Date
$threshold = 1
$creep = -4
$Cluster =  [bool]$false

################################################
#
# Is certsrv running? Is it a clustered CA?
# If clustered it is not running don't send an SMTP message
#
################################################
$service = get-service | where-Object {$_.name -eq "certsvc"}

if (!($service.Status -eq "Running"))
{
if($Cluster)
{
$evt_string = "Active Directory Certificate Services is not running on this node of the cluster. Exiting program."
write-debug "ADCS is not running. This is a clustered node. Exiting"
results $evt_string $EventInformation $SMTP
exit
}
else
{
$evt_string = "**** IMPORTANT **** IMPORTANT **** IMPORTANT ****" +  $newline + "Certsvc status is: " + $service.status + $newline
write-debug "ADCS is not running and not a clustered node. Not good."
results $evt_string $EventHigh $SMTP
exit
}
}
else
{
write-debug "Certsvc is running. Continue."
}

################################################
#
# Pull CRLs from Master and HTTP CDP locations
# Not going to bother with Active Directory since this
# is probably a Windows Enterprise CA (todo)
#
################################################
$CRL_Master = [Mono.Security.X509.X509Crl]::CreateFromFile($crl_master_path + $CRL_Name)
$web_client = New-Object System.Net.WebClient
$CDP1_CRL = [Mono.Security.X509.X509Crl]$web_client.DownloadData($CDP1_HTTP + $CRL_Name)
$CDP2_CRL = [Mono.Security.X509.X509Crl]$web_client.DownloadData($CDP2_HTTP + $CRL_Name)

################################################
#
# Debug section to give you the time/dates of the CRLs
#
################################################
if($debugpreference -eq "continue")
{
write-debug $newline
write-debug "Master CRL Values"
$debug_out = $CRL_Master.ThisUpdate.AddHours($creep)
write-debug "Master ThisUpdate $debug_out"
$debug_out = $CDP1_CRL.ThisUpdate.AddHours($creep)
write-debug "CDP1_CRL ThisUpdate: $debug_out"
$debug_out = $CDP2_CRL.ThisUpdate.AddHours($creep)
write-debug "CDP2_CRL ThisUpdate: $debug_out"
$debug_out = $CRL_Master.NextUpdate.AddHours($creep)
write-debug "Master NextUpdate: $debug_out"
$debug_out = $CDP1_CRL.NextUpdate.AddHours($creep)
write-debug "CDP1_CRL NextUpdate: $debug_out"
$debug_out = $CDP2_CRL.NextUpdate.AddHours($creep)
write-debug "CDP2_CRL NextUpdate: $debug_out"
write-debug $newline
}

################################################
#
# Determine the status of the master CRL
# Master and CDP CRLs have the same EffectiveDate (Mono = ThisUpdate)
#
################################################
if($CRL_Master.NextUpdate.AddHours($creep) -gt $time)
{
# This is healthy Master CRL
write-debug "Master CRL EffectiveDate: "
write-debug $CRL_Master.ThisUpdate.AddHours($creep)
write-debug "Time now is: "
write-debug $time
write-debug $newline
}
else
{
# Everything has gone stale, not good. Alert.
write-debug "Master CRL has gone stale"
$evt_string = "**** IMPORTANT **** IMPORTANT **** IMPORTANT ****" + $newline + "Master CRL: " + $CRL_Name + " has an EffectiveDate of: " + $CRL_Master.ThisUpdate.AddHours($creep) + " and an NextUpdate of: " + $CRL_Master.NextUpdate.AddHours($creep) + $newline + "Certsvc status is: " + $service.status
results $evt_string $EventHigh $SMTP
exit
}
################################################
#
# Determine what the status of the CDPs
# Does the Master and the CDP CRLs match up?
#
################################################
if (($CRL_Master.ThisUpdate -eq $CDP1_CRL.ThisUpdate) -and ($CRL_Master.ThisUpdate -eq $CDP2_CRL.ThisUpdate))
{
write-debug "All CRLs EffectiveDates match"
write-debug $CRL_Master.ThisUpdate
write-debug $CDP1_CRL.ThisUpdate
write-debug $CDP2_CRL.ThisUpdate
write-debug $newline
}
################################################
#
# New Master CRL, Update CDP CRLs if or or both are old
# would be nice to use the 'CRL Number'
# Compare the hash values of the Master CRL and CDP CRLs
# after the copy command to make sure the copy completed
#
################################################
elseif (($CRL_Master.ThisUpdate -gt $CDP1_CRL.ThisUpdate) -or ($CRL_Master.ThisUpdate -gt $CDP2_CRL.ThisUpdate))
{
# There is a new master CRL, copy to CDPs
write-debug "New master crl. Copy out to CDPs"
$source = Get-Item $crl_master_path$CRL_Name
Copy-Item $source $CDP1_UNC$CRL_Name
Copy-Item $source $CDP2_UNC$CRL_Name
# Compare the hash values of the master CRL to the CDP CRL
# If they do not equal alert via SMTP by setting the $SMTP boolian value to '$true'
$master_hash = get-hash $source
$cdp1_hash = get-hash $CDP1_UNC$CRL_Name
$cdp2_hash = get-hash $CDP2_UNC$CRL_Name
if(($master_hash.HashString -ne $cdp1_hash.HashString) -or ($master_hash.HashString -ne $cdp2_hash.HashString))
{
$evt_string = "CRL copy to CDP location failed:" +$newline +"Master CRL Hash: " +$master_hash.HashString +$newline + "CPD1  Hash:" +$cdp1_hash.HashString +$newline + "CDP2 Hash:" +$cdp2_hash.HashString +$newline
# Make sure the email alert goes out. Override the $SMTP variable
write-debug $newline
write-debug "CRLs copied to CDPs hash values do not match Master CRL Hash"
write-debug "Master CRL Hash value"
write-debug $master_hash.HashString
write-debug "CDP1 CRL Hash value"
write-debug $cdp1_hash.HashString
write-debug "CDP2 CRL Hash value"
write-debug $cdp2_hash.HashString
$SMTP = [bool]$true
results $evt_string $EventHigh $SMTP
exit
}
else
{
$evt_string = "New Master CRL published to CDPs. " + $CRL_Name + " has an EffectiveDate of: " + $CRL_Master.ThisUpdate.AddHours($creep) + " and an NextUpdate of: " + $CRL_Master.NextUpdate.AddHours($creep)
results $evt_string $EventInformation $SMTP
}
}
else
{
write-debug "logic bomb, can't determine where the Master CRL is in relationship to the CDP CRLs"
}
################################################
#
# Master CRL’s ThisUpdate time is in between the NextCRLPublish time and NextUpdate.
# Note Mono does not have a method to read 'NextCRLPublish'
# The CA Operator can define the '$threshold' at which that want to start receiving alerts
#
################################################
if (($CRL_Master.NextUpdate.AddHours($creep) -gt $time) -and ($CRL_Master.ThisUpdate.AddHours($creep) -lt $time))
{
write-debug "checking threshold"
# Is the Master CRL NextUpdate within the defined alert threshold?
if($CRL_Master.NextUpdate.AddHours(-($threshold - $creep)) -lt $time)
{
write-debug "***** WARNING ****** Master CRL NextUpdate has a life less than threshold."
write-debug $CRL_Master.NextUpdate.AddHours(-($threshold - $creep))
$evt_string = "***** WARNING ****** Master CRL NextUpdate has a life less than threshold of: " + $threshold + " hour(s)" + $newline + "Master CRLs NextUpdate is: " + $CRL_Master.NextUpdate.AddHours($creep) + $newline +"Certsvc service is: " + $service.Status
results $evt_string $EventWarning $SMTP
}
else
{
write-debug "Within the Master CRLs NextCRLPublish and NextUpdate period. Within threshold period."
write-debug $CRL_Master.NextUpdate.AddHours(-($threshold - $creep))
# Uncomment the following if you want notification on the CRLs
#$evt_string = "Within the Master CRLs NextCRLPublish and NextUpdate period. Alerts will be send at " + $threshold + " hour(s) before NextUpdate period is reached."
#results $evt_string $EventInformation $SMTP
}
}
else
{
write-debug "logic bomb, can't determine where we are in the threshold"
}