"Run" or "Run In Console"

Support for all customers who have purchased a SAPIEN PowerShell Studio product license. This forum does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
Kilsgaard
Posts: 11
Joined: Fri Feb 10, 2017 3:15 am

"Run" or "Run In Console"

Post by Kilsgaard » Fri May 11, 2018 4:49 am

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: 5190
Joined: Thu Aug 18, 2011 4:56 am

Re: "Run" or "Run In Console"

Post by davidc » Fri May 11, 2018 10:32 am

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: 11
Joined: Fri Feb 10, 2017 3:15 am

Re: "Run" or "Run In Console"

Post by Kilsgaard » Fri May 11, 2018 10:38 pm

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 547 times
Error Message Powershell Studio - Invoke-RestMethod.txt
(1.23 KiB) Downloaded 30 times
Error Message Powershell Studio - Invoke-RestMethod.png
Error Message Powershell Studio - Invoke-RestMethod.png (54.5 KiB) Viewed 547 times

User avatar
davidc
Posts: 5190
Joined: Thu Aug 18, 2011 4:56 am

Re: "Run" or "Run In Console"

Post by davidc » Mon May 14, 2018 9:35 am

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: 11
Joined: Fri Feb 10, 2017 3:15 am

Re: "Run" or "Run In Console"

Post by Kilsgaard » Tue May 15, 2018 12:12 pm

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: 5190
Joined: Thu Aug 18, 2011 4:56 am

Re: "Run" or "Run In Console"

Post by davidc » Tue May 15, 2018 2:52 pm

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. {
  4.  
  5.     if ($null -ne $item.Exception )
  6.  
  7.     {
  8.  
  9.         "-----------------------------------------`r`n{0}:`r`n-----------------------------------------`r`n {1}" -f $item.Exception.GetType().Name, $item.Exception.Message
  10.  
  11.         if ($null -ne $item.Exception.InnerException)
  12.  
  13.         {
  14.  
  15.             "   -> Inner Exception:`r`n      {0}:    `r`n      {1}" -f $item.Exception.InnerException.GetType().Name, $item.Exception.InnerException.Message
  16.  
  17.         }
  18.  
  19.     }
  20.  
  21.     else
  22.  
  23.     {
  24.  
  25.         '----------------------------------------- {0}' -f $item.ErrorDetails.Message
  26.  
  27.     }
  28.  
  29. }
Let's see if there are any hints in the inner exceptions.
David
SAPIEN Technologies, Inc.

User avatar
Kilsgaard
Posts: 11
Joined: Fri Feb 10, 2017 3:15 am

Re: "Run" or "Run In Console"

Post by Kilsgaard » Tue May 15, 2018 11:16 pm

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: 5190
Joined: Thu Aug 18, 2011 4:56 am

Re: "Run" or "Run In Console"

Post by davidc » Thu May 17, 2018 8:24 am

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: 11
Joined: Fri Feb 10, 2017 3:15 am

Re: "Run" or "Run In Console"

Post by Kilsgaard » Thu May 17, 2018 11:44 am

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 9 times

User avatar
davidc
Posts: 5190
Joined: Thu Aug 18, 2011 4:56 am

Re: "Run" or "Run In Console"

Post by davidc » Thu May 17, 2018 1:24 pm

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.