Created
February 9, 2018 18:05
-
-
Save Chirishman/a2cfa22f5a2d3cb2ea026b19f66b94ff to your computer and use it in GitHub Desktop.
Code examples for using ADAuth module to create Active Directory UD Login Pages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$FormLogin = New-UDAuthenticationMethod -Endpoint { | |
param([PSCredential]$Credentials) | |
Import-Module ADAuth | |
$AuthorizedGroup = 'Administrators' | |
if ($Credentials | ? {$_ | Test-ADCredential} | Test-ADGroupMembership -TargetGroup $AuthorizedGroup) { | |
New-UDAuthenticationResult -Success -UserName $Credentials.UserName | |
} | |
New-UDAuthenticationResult -ErrorMessage "You aren't $($Credentials.UserName)!!!" | |
} | |
$LoginPage = New-UDLoginPage -AuthenticationMethod @($FormLogin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function New-UDADLoginPage { | |
Param( | |
[Parameter()] | |
[string[]]$Group = 'Administrators' | |
) | |
$FormLogin = New-UDAuthenticationMethod -Endpoint ([scriptblock]::Create(" | |
param([PSCredential]`$Credentials) | |
Import-Module ADAuth | |
if (`$Credentials | ? {`$_ | Test-ADCredential} | Test-ADGroupMembership -TargetGroup @('$($Group -join "','")')) { | |
New-UDAuthenticationResult -Success -UserName `$Credentials.UserName | |
} | |
New-UDAuthenticationResult -ErrorMessage ""You aren't `$(`$Credentials.UserName)!!!"" | |
")) | |
New-UDLoginPage -AuthenticationMethod @($FormLogin) -ErrorAction Stop | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment