"Run" or "Run In Console"

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
Kilsgaard
Posts: 25
Last visit: Fri Jan 26, 2024 11:37 am
Has voted: 1 time

"Run" or "Run In Console"

Post by Kilsgaard »

Product, version and build: 5.5.152
32 or 64 bit version of product: 64bit
Operating system: Windows 10 1803
32 or 64 bit OS: 64bit

Hi

I need a bit of help, i do not understand the following.

I have the following Powershell code:

Code: Select all

$NAVResult = Invoke-RestMethod -Uri 'https://[Server]:[Port]/[Service]/OData/Company(''[Company]'')/ContiniaUserList(User_ID=''KMC%5CAQH'')?`$format=json' -Method Get -Credential
If i hit Run in PowerShell Studio, the code fails because of the: "\" (%5C) in (User_ID=''KMC%5CAQH''), if i find a username without "\" the code works ex. (User_ID=''UPGKI'').

If I Run the code with "Run in Console" or in a PowerShell Prompt, the code works perfect.

Do you think this is at feature or a bug?

Thanks on adwance :-)
/Graves
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Run" or "Run In Console"

Post by davidc »

What is the actual error message that it produces?

Please verify that you have the same platform settings (x64 /x86 / Elevated) when running the script in PowerShell Studio's internal host as you do with the console.
David
SAPIEN Technologies, Inc.
User avatar
Kilsgaard
Posts: 25
Last visit: Fri Jan 26, 2024 11:37 am
Has voted: 1 time

Re: "Run" or "Run In Console"

Post by Kilsgaard »

Hi David

Thanks for your response.

I have attached a screendump of the errormessage i get when i select run from Powershell studio.
If i select: "Run in Console" from PowerShell Studio the script runs perfect.

Is the platform setting not the same if i select "Run" or "Run in Console" in Powershell Studio?
The script is running in "Powershell 5 - Not elevated", but i have tried running it elevated and that has no change..

Please tell me if you need more information?

Best Regards
/Graves
Attachments
PowerShell Studio - Settings.png
PowerShell Studio - Settings.png (5.62 KiB) Viewed 4822 times
Error Message Powershell Studio - Invoke-RestMethod.txt
(1.23 KiB) Downloaded 167 times
Error Message Powershell Studio - Invoke-RestMethod.png
Error Message Powershell Studio - Invoke-RestMethod.png (54.5 KiB) Viewed 4822 times
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Run" or "Run In Console"

Post by davidc »

Our internal host isn't doing anything special other than submitting the script to the PowerShell engine. The script is loaded by the PowerShell engine as is, so there has to be an external difference or some other factor at play.

1. Do you have any configurations in a profile? Note: Our internal host doesn't load any profiles.
2. Another factor could be firewall permissions.
3. Are there any other errors in the $Error variable? Output every error within the variable to see if there is any other relevant information.
David
SAPIEN Technologies, Inc.
User avatar
Kilsgaard
Posts: 25
Last visit: Fri Jan 26, 2024 11:37 am
Has voted: 1 time

Re: "Run" or "Run In Console"

Post by Kilsgaard »

Hi David

I have joust tested on my other developing computer, where i have PowerShell studio installed, but it gives me the same errors.

I cannot see that it could be firewall, the same Invoke-Restmethod is working perfect with the: "Run" command, if i am not using "\" (%5C).

Can you help me giving more debug data?
  • What error command output should i give you?
  • What should I look for regarding profile (I have not configured anything special that i know of)?
Could I offer you to join me on a remote session, so I could show you the problem?

Thanks on advance :-)
/Graves
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Run" or "Run In Console"

Post by davidc »

It could be that the Uri is getting decoded ( E.g. %5C to \) and in the other case it is not. I'm not sure what would cause the difference.

Do you get the same error if you use the Run Selection command?

Also, try adding this at the end of your script that fails:
  1. foreach ($item in $Error)
  2. {
  3.     if ($null -ne $item.Exception )
  4.     {
  5.         "-----------------------------------------`r`n{0}:`r`n-----------------------------------------`r`n {1}" -f $item.Exception.GetType().Name, $item.Exception.Message
  6.         if ($null -ne $item.Exception.InnerException)
  7.         {
  8.             "   -> Inner Exception:`r`n      {0}:    `r`n      {1}" -f $item.Exception.InnerException.GetType().Name, $item.Exception.InnerException.Message
  9.         }
  10.     }
  11.     else
  12.     {
  13.         '----------------------------------------- {0}' -f $item.ErrorDetails.Message
  14.     }
  15. }
Let's see if there are any hints in the inner exceptions.
David
SAPIEN Technologies, Inc.
User avatar
Kilsgaard
Posts: 25
Last visit: Fri Jan 26, 2024 11:37 am
Has voted: 1 time

Re: "Run" or "Run In Console"

Post by Kilsgaard »

Hi David

In the code that works there are no "\" (%5C) present, the script only fails when a "\" (%5C) is in the url, and i select "Run" instead of run in console.

When I run the code you gave me I get this:
>> Debugging (OData Test.ps1) Script...
>> Platform: V5 64Bit (STA)
ERROR: Invoke-RestMethod : Bad Request - Error in query syntax.
OData Test.ps1 (21, 14): ERROR: At Line: 21 char: 14
ERROR: + ... NAVResult = Invoke-RestMethod -Uri 'https://TEST-NAV01.kmc.dk:7148/NA ...
ERROR: + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR: + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
ERROR: + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
-----------------------------------------
WebException:
-----------------------------------------
Fjernserveren returnerede en fejl: (400) Forkert anmodning.
[In English]: "The Remote servere returned an error: (400) Wrong request"
>> Script Ended

The same happends when i mark the query and select "Run Selection", it fails when the url contains "\" (%5C) and there is success when there is no "\".

Regards
/Graves
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Run" or "Run In Console"

Post by davidc »

Out of curiosity, what happens when you package the script into an executable? Try the both the Console and the Windows Application engines.

Also, test running the script from the ISE. I just want to try this in some different hosts to see if it is only our hosts or if others are affected.
David
SAPIEN Technologies, Inc.
User avatar
Kilsgaard
Posts: 25
Last visit: Fri Jan 26, 2024 11:37 am
Has voted: 1 time

Re: "Run" or "Run In Console"

Post by Kilsgaard »

Hi David

Please see attached document, where i have testet on different computers and with different tools.

I can only get the error when I select "Run" or "Run Selection" from PowerShell Studio, in all other cases the script works perfect with or whithout "\" (%5C) in the username parameter in the URL.

If you are not convinced, please let me show you through a remote session or similar?

Best Regards
/Graves
Attachments
Powershell Test.pdf
(399.1 KiB) Downloaded 123 times
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: "Run" or "Run In Console"

Post by davidc »

I'm convinced, no need for the remote session. I'm just trying to isolate the problem to a particular host so I can have the Dev team investigate. I'm also trying to reproduce this on my end.

I noticed you have STA mode checked. Out of curiosity, can you uncheck that option to see if it makes a difference?
Does the error also occur when you have 32 Bit or V2 selected?
David
SAPIEN Technologies, Inc.
This topic is 5 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.