PowerShell scripts don't work anymore in new versie 6.1.0

Hi there,

Yesterday we have updatet our EasyMorph Desktop from 5.9.7 to 6.1.0.
Now this powershell script stopt working:

#Powershell script om SOAP GET request doen. GetData

[String]$Token = "1{own token}"
[String]$connectorId = "{own connectorid}"
[Int]$Skip = 0
[Int]$Take = 100000000
[String]$FiltersXml = ""

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;
$WebServiceProxy = New-WebServiceProxy -Uri "{own url}"
$WebServiceProxy.GetData($Token, $connectorId, $FiltersXml, $Skip, $Take)

Current Error messages is: Errors
The 'New-WebServiceProxy' command was found in the module 'Microsoft.PowerShell.Management', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Management'.
You cannot call a method on a null-valued expression.
Execution failed.

If I run this script stand alone in PowerShell outside of EasyMorph it runs fine.

Please could you help us?

Kind Regards,
Colin Lenting

Hi Colin,

In version 6.0.0, we migrated our products from .NET Framework 4.8 to .NET 8, which is not compatible with PowerShell 5.1 and can only work with PowerShell 7.4.

New-WebServiceProxy is unavailable in PowerShell 7.4 because it relies on the legacy .NET Framework module (System.Web.Services) that was not ported to modern .NET.

Temporary workaround

As a temporary workaround, you can try the following.

1. Move your script to a separate PowerShell script file:

#Powershell script om SOAP GET request doen. GetData

[CmdletBinding()]
param (
    [Parameter(Mandatory = $true)]
    [string]$OwnUrl,

    [Parameter(Mandatory = $true)]
    [string]$OwnToken,

    [Parameter(Mandatory = $true)]
    [string]$OwnConnectorId
)

[Int]$Skip = 0
[Int]$Take = 100000000
[String]$FiltersXml = ""
[String]$Token = "1$($OwnToken)"

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12;

$WebServiceProxy = New-WebServiceProxy -Uri $OwnUrl
$WebServiceProxy.GetData($Token, $OwnConnectorId, $FiltersXml, $Skip, $Take)

2. Replace your PowerShell action with the Run program action, configured as follows:

Application: leave empty
Working directory: leave empty
Arguments: choose text and add the following command:

powershell.exe -NoProfile -ExecutionPolicy Bypass -File "<path to the file created on step 1>" -OwnUrl "{own url}" -OwnToken "{own token}" -OwnConnectorId "{own connectorid}"

Capture output: checked

If your script uses other EasyMorph parameters, you'll need to provide them as PowerShell script parameters as well.

Recommended migration

We recommend rewriting your scripts to use the Invoke-WebRequest method. This will looks something like this:

#Powershell script om SOAP GET request doen. GetData

[String]$Token = "1{own token}"
[String]$connectorId = "{own connectorid}"
[Int]$Skip = 0
[Int]$Take = 100000000
[String]$FiltersXml = ""
[String]$url = "{own url}"

# Build SOAP envelope (adjust XML namespace and element names to match your service WSDL)
$soapEnvelope = @"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetData xmlns="http://tempuri.org/">
      <Token>$Token</Token>
      <connectorId>$connectorId</connectorId>
      <FiltersXml>$FiltersXml</FiltersXml>
      <Skip>$Skip</Skip>
      <Take>$Take</Take>
    </GetData>
  </soap:Body>
</soap:Envelope>
"@

$headers = @{
    "SOAPAction" = "$url/GetData" # Adjust to match your endpoint's SOAPAction
}

$response = Invoke-WebRequest -Uri $url -Method Post -ContentType "text/xml; charset=utf-8" -Headers $headers -Body $soapEnvelope
[xml]$xmlResult = $response.Content

P.S. Are you also running this script in EasyMorph Sever/Hub?

Hi Andrew,

Thank you for your answer. We work in EasyMorph Desktop version.
We have found the workaround with the run program action. Where we can run Powershell in our own system version of Powershell and .Net 4.8. This works for now.

Kind Regards,
Colin

Hi Colin,

You are welcome!

Best Regards,
Andrew