Running PowerShell Studio 2021. V5.8.16
Hey Folks. I'm building a simple form-based script, or better call it a form-based tool for our HelpDesk reps to be able to quickly assist people in the organization with basic requests (Reset Password, Unlock Account, Add and Remove users from Active Directory Groups and etc.)
The Active Directory coding part I can do in my sleep as I've been writing PowerShell Automation codes for various Active Directory functions for a very long time now.
I'm however stumped by something which is probably trivial yet still escapes me.
The code below is meant to prevent anyone who is not in a predetermined Security group to be able to launch the internal scripts and forms, to that end, I need to allow the users to log in, I then check the credentials against the Active Directory LDAP service and show another form wth the actions the user can do based on his security group memberships.
I want the "Login" Button (see form design attached) the be invisible unless both the "UserName" and "Password" fields have any values OR the "Use Network credentials" checkbox is checked.
- $formLogin_Load={
- $buttonLogin.Visible = $false
- $buttonLogin.Enabled = $false
- }
- function Test-UserInput
- {
- return $((($txt_pw.Text -eq "") -or ($txt_usr.Text -eq "")) -or (($txt_pw.Text -eq $null) -or ($txt_usr.Text -eq $null)))
- }
- function Show-LoginButton
- {
- {
- $buttonLogin.Visible = $true
- $buttonLogin.Enabled = $true
- }
- }
- function Hide-LoginButton
- {
- {
- $buttonLogin.Visible = $false
- $buttonLogin.Enabled = $false
- }
- }
- $checkboxUseNetworkCredential_CheckedChanged={
- #TODO: Place custom script here
- if ($checkboxUseNetworkCredential.Checked)
- {
- $txt_pw.Enabled = $false
- $txt_pw.Text = $null
- $txt_usr.Enabled = $false
- $txt_usr.Text = $null
- Show-LoginButton
- }
- else
- {
- $txt_pw.Enabled = $true
- $txt_usr.Enabled = $true
- Hide-LoginButton
- }
- }
- $buttonLogin_Click={
- #TODO: Place custom script here
- if ($checkboxUseNetworkCredential.Checked)
- {
- $Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
- }
- else
- {
- $Operator_uName = $txt_usr.Text
- $Operator_PW = $txt_pw.Text
- }
- }
- $txt_usr_TextChanged={
- #TODO: Place custom script here
- if (Test-UserInput)
- {
- Write-Host "At least one is empty"
- Hide-LoginButton
- }
- else
- {
- Write-Host "Neither are empty"
- Show-LoginButton
- }
- }
- $txt_pw_TextChanged = {
- #TODO: Place custom script here
- if (Test-UserInput)
- {
- Write-Host "At least one is empty"
- Hide-LoginButton
- }
- else
- {
- Write-Host "Neither are empty"
- Show-LoginButton
- }
- }
Any help you can provide on the matter will be greatly appreciated.
Sincerely,
Davsank.