-
Notifications
You must be signed in to change notification settings - Fork 0
/
5.1-Simple-AuthnPolicy.ps1
55 lines (55 loc) · 1.46 KB
/
5.1-Simple-AuthnPolicy.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
<#
Engineering Active Directory by Evgenij Smirnov
Chapter 5: Engineering Authentication
Code 5.1: Create a simple Authentication Policy
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)]
[string]$PolicyName,
[Parameter(Mandatory=$false)]
[ValidateRange(10,65535)]
[int]$TGTLifeTimeMinutes = 240,
[Parameter(Mandatory=$true)]
[string]$ComputerGroup
)
try {
Import-Module ActiveDirectory -EA Stop
} catch {
Write-Warning $_.Exception.Message
exit
}
try {
$existingPolicy = Get-ADAuthenticationPolicy -Filter {Name -eq $PolicyName} -EA Stop
} catch {
Write-Warning $_.Exception.Message
exit
}
if ($null -ne $existingPolicy) {
Write-Warning 'Policy already exists in this forest!'
exit
}
try {
$adGroup = Get-ADGroup -Filter {Name -eq $ComputerGroup} -EA Stop
} catch {
Write-Warning $_.Exception.Message
exit
}
if ($null -eq $adGroup) {
Write-Warning 'Computer group does not exist!'
exit
}
$groupSID = $adGroup.SID.Value
$fromSDDL = "O:SYG:SYD:(XA;OICI;CR;;;WD;((Member_of_any {SID($groupSID)}) || (Member_of_any {SID(ED)})))"
$authNPolicyParms = @{
'Name' = $PolicyName
'Enforce' = $true
'UserTGTLifetimeMins' = $TGTLifeTimeMinutes
'UserAllowedToAuthenticateFrom' = $fromSDDL
}
try {
New-ADAuthenticationPolicy @authNPolicyParms -EA Stop
Write-Host 'Authentication Policy created successfully' -ForegroundColor Green
} catch {
Write-Warning $_.Exception.Message
}