Skip to content

Instantly share code, notes, and snippets.

@Chirishman
Created February 9, 2018 18:05
Show Gist options
  • Save Chirishman/a2cfa22f5a2d3cb2ea026b19f66b94ff to your computer and use it in GitHub Desktop.
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
$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)
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