i have been reading many posts in this forum about how to add a user/pass mechanism to a form.
this is what i have but it only passes if i run it from a computer that a domain admin is logged on to localy
Code: Select all
function Test-Credentials ($cred)
{
$username = $cred.username
$password = $cred.GetNetworkCredential().password
# Get current domain using logged-on user's credentials
$CurrentDomain = "LDAP://" + ([ADSI]"").distinguishedName
$domain = New-Object System.DirectoryServices.DirectoryEntry($CurrentDomain, $UserName, $Password)
if ($domain.name -eq $null)
{
[void][System.Windows.Forms.MessageBox]::Show('Authentication failed - please verify your username and password.', 'Fail')
$form1.Close() #terminate the script.
# return #use return if in an event block
}
else
{
[void][System.Windows.Forms.MessageBox]::Show("Successfully authenticated with domain $($domain.name)", 'Success')
}
}
$form1_Shown={
#TODO: Place custom script here
$creds = Get-Credential
Test-Credentials $Creds
}
if i run the function from domain User pc in ISE or Powershell Studio in debug - it works...
not sure what am i missing...
thanks
Sean