To help you better we need some information from you.
*** Please fill in the fields below if you are currently using a Trial Version of the Product. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build: Sapien powershell studio 2012, 3.1.19
32 or 64 bit version of product: 64 bit
Operating system: Windows 10
32 or 64 bit OS: 64 bit
*** Please add details and screenshots as needed below. ***
My program runs perfectly on a Windows 7 workstation, but does not function properly on Windows 10 workstation.
Below is a snippet of the script
if(($textbox2.Text -eq "") -or ($textbox2.Text -eq $null))
{
[void][System.Windows.Forms.MessageBox]::Show("Enter email address to send the info to !","No receiver specified")
$buttonGO.Enabled = $true
}
else
{
$validation = $null
$validation = Get-ADUser -filter * | where {$_.UserPrincipalName -eq $textbox2.Text}
if($validation -eq $null)
{
[void][System.Windows.Forms.MessageBox]::Show("Incorrect recipient email address","Check email address")
$errorFlag = 1
}
}
For some reason it keeps going in the else loop even when i am entering the correct email address in textbox2.
DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM
Incorrect loop execution on Windows 10
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Incorrect loop execution on Windows 10
I need more information in order to help you.
-Are there are any error messages?
-What version of PowerShell are you running?
-Does your script run in the ISE?
-Are you able to post more of your script?
-Are there are any error messages?
-What version of PowerShell are you running?
-Does your script run in the ISE?
-Are you able to post more of your script?
Brittney
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Incorrect loop execution on Windows 10
[Topic moved by moderator]
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Incorrect loop execution on Windows 10
The correct way to test a controls contents is like this:
This:
if(($textbox2.Text -eq "") -or ($textbox2.Text -eq $null))
Should be this:
if($textbox2.Text){
When designing logic we should always try to use positive testing and not negative as it is easier to understand and lees prone to errors.
Here is how to structure this test, Notice it uses only positive logic which also simplifies the code.
Also you are returning ALL users then testing which would be very inefficient on a large network. The filter will return a user if found or $null if not found.
The positive logic approach is easier to understand and read. It also makes the code much simpler.
I would remove the test of the textbox in favor of validation on the textbox if this is not in the "validated" event.
This:
if(($textbox2.Text -eq "") -or ($textbox2.Text -eq $null))
Should be this:
if($textbox2.Text){
When designing logic we should always try to use positive testing and not negative as it is easier to understand and lees prone to errors.
Here is how to structure this test, Notice it uses only positive logic which also simplifies the code.
Code: Select all
if($textbox2.Text){
if(Get-ADUser -filter "UserPrincipalName -eq '$($textbox2.Text)'"){
$buttonGO.Enabled = $true
}else{
[void][System.Windows.Forms.MessageBox]::Show('Incorrect recipient email address','Check email address')
}
}else{
[void][System.Windows.Forms.MessageBox]::Show("Enter email address to send the info to !","No receiver specified")
}
The positive logic approach is easier to understand and read. It also makes the code much simpler.
I would remove the test of the textbox in favor of validation on the textbox if this is not in the "validated" event.