The script below works in ISE and it runs fine before I export an exe. As soon as I export an exe through PF it quits functioning properly. It works when I enter a valid password; however it appears to skip the first if -eq false line through the exe. I've run it through debug and it functions properly; so I'm missing something. Any help will be appreciated.
if ($Error | Select-String -SimpleMatch "Invalid") {
$global:SQProdCheck = $false}
elseif ($Error | Select-String -SimpleMatch "Login failed") {
$global:SQProdCheck = $false}
elseif ($Error | Select-String -SimpleMatch "expired") {
$global:SQProdCheck = "Expired"}
else {$global:SQProdCheck = $true}
If ($global:SQProdCheck -eq $true){
}
elseif ($global:SQProdCheck -eq $false) {
$initAnswerSQL = "The User ID and password you entered are not correct for Sybase Production. Please try again."
$global:SQL = $host.ui.PromptForCredential("SQL Credentials", "$initAnswerSQL", "$env:username", "")
$global:GetSQL = $global:SQL.GetNetworkCredential()
$global:SQUser = $global:GetSQL.username
$global:SQPassword = $global:GetSQL.password
$global:SQProdCheck = $true
}
Prompts in PrimalForms
- tremdaniel
- Posts: 21
- Last visit: Thu Feb 12, 2015 11:11 am
Prompts in PrimalForms
BTW I'm currently running 2.0.8 and I know about $host.ui.PromptForCredential. This is not the issue. Thanks again.
Prompts in PrimalForms
I'm not quite sure I understand what is wrong. Can you elaborate on what is not function correctly? Please clarify what you expect it to do and what actually happens. Thank you, David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Prompts in PrimalForms
Also you should update to the latest build and see if that makes a difference as well. David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- tremdaniel
- Posts: 21
- Last visit: Thu Feb 12, 2015 11:11 am
Prompts in PrimalForms
I guess that would help! Ok; so I'd like for it to check $error for a string of text and then assign a value to $global:SQProdCheck. Once the value has been assigned it will do nothing if it's $true and if it's $false, it will prompt the user to enter the password again (this is the part that doesn't work in the exe). In the exe if the password is entered correctly it continues on. If the password is entered incorrectly it continues on. It's ignoring the elseif($global:SQProdCheck -eq $false){do this} portion.
Unfortunately I can't update to the latest build due to my second post. I've had others on my team export this to exe using the latest build and they run into the same issue.tremdaniel2011-10-27 15:15:44
Unfortunately I can't update to the latest build due to my second post. I've had others on my team export this to exe using the latest build and they run into the same issue.tremdaniel2011-10-27 15:15:44
Prompts in PrimalForms
How is the $Error variable assigned? If this variable is just a string then you need not pipe it to Select-String. Instead you can use the following: $Error -eq "Invalid" I would recommend using a message to determine the value of SQProdCheck, for example:Write-Host
$global:SQProdCheckYou will also need to use command line host to see the message. Also you can change: elseif ($global:SQProdCheck -eq $false) {...} to simply (because you already checked if it was true above)else {...} It maybe that the variable is a null value for some reason. Another good test is to always run the the prompt credential line to make sure it functions with the packager settings. David davidc2011-10-27 16:12:31
$global:SQProdCheckYou will also need to use command line host to see the message. Also you can change: elseif ($global:SQProdCheck -eq $false) {...} to simply (because you already checked if it was true above)else {...} It maybe that the variable is a null value for some reason. Another good test is to always run the the prompt credential line to make sure it functions with the packager settings. David davidc2011-10-27 16:12:31
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- tremdaniel
- Posts: 21
- Last visit: Thu Feb 12, 2015 11:11 am
Prompts in PrimalForms
After cleaning it up a little (thank you for helping me see the redundancy), it's still returning the same thing, but I do know what the problem is. $Error is a System.Management.Automation.ErrorRecord. This is what my errors are being returned to. Outside of exe it will look for "login failed" within this object via -simplematch, but within the exe it never sees it. I verified this by hard coding an $error1 that equals the text I was looking for (on a failed attempt). I've verified it is returning the following error:
[Sybase][ODBC Driver][Adaptive Server Enterprise]Login failed.
Is there a better way to check that object for "Login failed"?
Thanks again for the assistance with this.tremdaniel2011-10-27 17:24:22
[Sybase][ODBC Driver][Adaptive Server Enterprise]Login failed.
Is there a better way to check that object for "Login failed"?
Thanks again for the assistance with this.tremdaniel2011-10-27 17:24:22
Prompts in PrimalForms
Unfortunately I'm not familiar with the error type and this is really beyond the scope of this forum. ScriptingAnswers.com is usually better suited to answer these types of questions. But if the object is an ErrorRecord (which I looked in the Object Browser and used it to linked to the MSDN), then you can use the following property: $Error.ErrorDetails.MessageIt should contain the message you want, but then again I'm not familiar with the object. If you ask around the scripting forums you might find a better solution. David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- tremdaniel
- Posts: 21
- Last visit: Thu Feb 12, 2015 11:11 am
Prompts in PrimalForms
The only reason I posted it here is because it works everywhere except for the exe. That's just what I've narrowed it down to.
Prompts in PrimalForms
Since I don't have the script it is hard for me to determine the problem. So the issue you are encountering is with the ErrorRecord and not the prompt, correct? David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.