Product: PowerShell Universal
Version: 1.4.7
Hello,
We recently purchased an Enterprise License and are setting the product up. We hooked up AD using this function:
Code
$Result = [Security.AuthenticationResult]::new()
#if ($Credential.UserName -eq ‘Admin’)
#{
$Result.UserName = ‘Admin’
$Result.Success = $true
#}
#$Result
Function Test-Credential {
[OutputType([Bool])]
Param (
[Parameter(
Mandatory = $true,
ValueFromPipeLine = $true,
ValueFromPipelineByPropertyName = $true
)]
[Alias(
'PSCredential'
)]
[ValidateNotNull()]
[System.Management.Automation.PSCredential]
[System.Management.Automation.Credential()]
$Credential,
[Parameter()]
[String]
$Domain = $Credential.GetNetworkCredential().Domain
)
Begin {
[System.Reflection.Assembly]::LoadWithPartialName("System.DirectoryServices.AccountManagement") |
Out-Null
$principalContext = New-Object System.DirectoryServices.AccountManagement.PrincipalContext(
[System.DirectoryServices.AccountManagement.ContextType]::Domain, $Domain
)
}
Process {
foreach ($item in $Credential) {
$networkCredential = $Credential.GetNetworkCredential()
Write-Output -InputObject $(
$principalContext.ValidateCredentials(
$networkCredential.UserName, $networkCredential.Password
)
)
}
}
End {
$principalContext.Dispose()
}
}
if (Test-Credential -Credential $Credential) {
$Result.UserName = $Credential.UserName
$Result.Success = $true
}
$Result
Users can login successfully, however, they are given administrator role. Can I change this to default to reader role unless someone promotes the account?