-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigure-ADCS.ps1
73 lines (61 loc) · 1.79 KB
/
Configure-ADCS.ps1
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<#
.SYNOPSIS
Run get-help -example Configure-ADCS.ps1 for examples
.EXAMPLE
.\Configure-ADCS.ps1 -Verbose
#>
[CmdletBinding()]
param (
)
#region CAPolicy
Write-Verbose "Creating CAPOlicy.inf file"
$file = 'C:\Windows\CAPolicy.inf'
new-item -ItemType file -Path $file
$content = '[Version]
Signature="$Windows NT$"
[PolicyStatementExtension]
Policies=InternalPolicy
[InternalPolicy]
OID= 1.2.3.4.1455.67.89.5
Notice="Legal Policy Statement"
[Certsrv_Server]
RenewalKeyLength=2048
RenewalValidityPeriod=Years
RenewalValidityPeriodUnits=10
LoadDefaultTemplates=0
AlternateSignatureAlgorithm=1'
$content | Set-content -Path $file
#endregion
#region Install feature
Write-Verbose "Installing ADCS role"
Add-WindowsFeature Adcs-Cert-Authority -IncludeManagementTools
start-sleep -Seconds 300
#endregion
#region Configure ADCS
Write-Verbose "Configuring ADCS"
Install-ADcsCertificationAuthority `
-Credential (Get-Credential) `
-CAType 'EnterpriseRootCa' `
-CACommonName $env:COMPUTERNAME `
-CADistinguishedNameSuffix ([ADSI]"LDAP://RootDSE").rootDomainNamingContext.value `
-CryptoProviderName 'RSA#Microsoft Software Key Storage Provider' `
-KeyLength 2048 `
-HashAlgorithmName 'SHA256' `
-ValidityPeriod 'Years' `
-ValidityPeriodUnits 10 `
-DatabaseDirectory 'C:\windows\system32\certLog' `
-LogDirectory 'c:\windows\system32\CertLog' `
-Force
#endregion
#region Certutil
Write-Verbose "Running Certutil code"
Certutil -setreg CA\CRLPeriodUnits 1
Certutil -setreg CA\CRLPeriod "Weeks"
Certutil -setreg CA\CRLDeltaPeriodUnits 1
Certutil -setreg CA\CRLDeltaPeriod "Days"
Certutil -setreg CA\CRLOverlapPeriodUnits 12
Certutil -setreg CA\CRLOverlapPeriod "Hours"
Certutil -setreg CA\ValidityPeriodUnits 5
Certutil -setreg CA\ValidityPeriod "Years"
Certutil -setreg CA\AuditFilter 127
#endregion