Issues with 2019 install and Invoke-WebRequest

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 3 weeks 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
CodSup01
Posts: 9
Last visit: Mon Feb 13, 2023 1:44 am

Issues with 2019 install and Invoke-WebRequest

Post by CodSup01 »

PowerShell Studio 2019 (64 Bit)
Build: v5.6.159
OS: Windows Server 2012 R2 Standard (64 Bit)
Build: v6.3.9600.0

Hi, I have a project originally created in Powershell Studio 2017 but have recently upgraded to 2019 to take advantage of some of the new features. When running the form application many of my custom modules and functions now fail (mainly those passing credentials, but this could be a red herring), yet when compiling the project into an executable everything works fine.

The form code, and filesystem structure of files has not changed at all. The project is set to "V5 - 64bit", yet the Console (using 64-bit) loads the module fine. Note I have upgraded to the latest build released last week to see if this resolved the problem. The error is:

Code: Select all

>> Running (Veeam-Backups.psproj) Project Script...
>> Platform: V5 64Bit (STA) (Forced)
ERROR: Invoke-CWMWebRequest :
CWManage.psm1 (417, 19): ERROR: At Line: 417 char: 19
ERROR: + ...        $Result = Invoke-CWMWebRequest -Arguments $WebRequestArguments
ERROR: +                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
ERROR:     + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-CWMWebRequest
Also, functions that I have located in "Globals.ps1" are not recognised on my form, so these too fail when running the form. An example below, a button with Get-Credential then fires a function with authentication for an HTTP API connection:

Code: Select all

ERROR: Invoke-webrequest : Configuration system failed to initialize
Globals.ps1 (96, 12): ERROR: At Line: 96 char: 12
ERROR: + ...   $result = Invoke-webrequest -UseBasicParsing -Uri $url -Body $body  ...
ERROR: +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ERROR:     + CategoryInfo          : NotSpecified: (:) [Invoke-WebRequest], ConfigurationErrorsException
ERROR:     + FullyQualifiedErrorId : System.Configuration.ConfigurationErrorsException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
ERROR:
ERROR: ConvertFrom-Json : Cannot bind argument to parameter 'InputObject' because it is null.
I've gone so far as uninstalling Powershell Studio 2019 from the box and cleansing the filesystem and registry, and reinstalling. Fortunately I can revert my machine to a prior backup where Studio 2017 is still operational with my project, but I could really use some help here.

I'm going to try a fresh install on another machine, even with just a trial to be honest as I can test a blank form with the module and see if it connects, will report back with my findings.

Edit: Same issue on a fresh install on another computer, have updated the title as both the functions and module contain Invoke-WebRequest (to independent systems) so am wondering if this is the cause.
User avatar
Olga_B
Site Admin
Posts: 196
Last visit: Mon Mar 25, 2024 11:57 am

Re: Issues with 2019 install and Invoke-WebRequest

Post by Olga_B »

Looks like your custom modules were not added to cache
Please check if they are checked in the PowerShell Cache Editor
User avatar
CodSup01
Posts: 9
Last visit: Mon Feb 13, 2023 1:44 am

Re: Issues with 2019 install and Invoke-WebRequest

Post by CodSup01 »

Hi,

The module is in the cache and the problem also relates to functions.
User avatar
Olga_B
Site Admin
Posts: 196
Last visit: Mon Mar 25, 2024 11:57 am

Re: Issues with 2019 install and Invoke-WebRequest

Post by Olga_B »

If you can, please zip and load up the original file(s), so that we can attempt to recreate the issue:

https://www.sapien.com/support/upload
User avatar
CodSup01
Posts: 9
Last visit: Mon Feb 13, 2023 1:44 am

Re: Issues with 2019 install and Invoke-WebRequest

Post by CodSup01 »

I've uploaded a test file, it worked in Powershell Studio 2017 but not in Powershell Studio 2019.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Issues with 2019 install and Invoke-WebRequest

Post by davidc »

It is possible that PowerShell Studio's internal script hosts do not have the necessary firewall permissions to communicate.

Please try adding firewall exceptions for the ScriptDriver*.exe executables located the following folders:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2019\Debugger64\
C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2019\Debugger32\
David
SAPIEN Technologies, Inc.
User avatar
CodSup01
Posts: 9
Last visit: Mon Feb 13, 2023 1:44 am

Re: Issues with 2019 install and Invoke-WebRequest

Post by CodSup01 »

No dice even with the firewall disabled on all profiles.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Issues with 2019 install and Invoke-WebRequest

Post by davidc »

Try placing a try catch around the Invoke-WebRequest:

Code: Select all

try
{
	Invoke-RestMethod -Uri $URI -Method Post -Body $BulkBody -Headers $Headers | Out-Null
}
catch
{
	Write-Output $_.Exception.Message
	if ($_.Exception.InnerException)
	{
		Write-Output $_.Exception.InnerException.Message
	}
}
If there is an inner exception, it might provide a clue as to the problem.
David
SAPIEN Technologies, Inc.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Issues with 2019 install and Invoke-WebRequest

Post by davidc »

I noticed you are using a https urls. I made a change to the ScriptDriver config files for PowerShell Studio for testing purposes:
scriptdriver64 config.zip
(761 Bytes) Downloaded 144 times
Please update them in the following folder and see if it makes a difference:

C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2019\Debugger64\

I recommend backing up the original config files before replacing them.
David
SAPIEN Technologies, Inc.
User avatar
CodSup01
Posts: 9
Last visit: Mon Feb 13, 2023 1:44 am

Re: Issues with 2019 install and Invoke-WebRequest

Post by CodSup01 »

Hi David,

Thanks for the files and further advice on capturing the error. Unfortunately the files did not help, however the following inner exception was found for both the original and new:
"Unrecognized configuration section uri. (C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2019\Debugger64\scriptdriver64.exe.Config line 7)"
This topic is 5 years and 3 weeks 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.