PowerShell REST Error

I have a PowerShell module with a number of scripts that do REST calls to Epicor Functions so they can perform updates on a newly restored PILOT or TEST environment, the REST calls to these Functions do successfully trigger them run. I am now trying to call Ice.LIB.ClientFunctionSvc/SetIsProductionInstance and I get a error I cannot get past. I am able to successfully make the REST call using both Swagger and Postman and it update the Environment’s Production status.

Here is the PowerShell Script, the $pass and $user variables are set as global in the module and used for all other REST call that are working

function Remove-ProductionStatus {
[string] $AppEnv

$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)

$params = @{
    'Uri' = 'https://[Epicor Server URL]/' + $AppEnv + '/api/v2/odata/GRC/Ice.LIB.ClientFunctionSvc/SetIsProductionInstance'
    'Method' = 'POST'
    'ContentType' = 'application/json'
    'Headers' = @{'X-Api-key' = $token

$body = @{ 'isProduction' = $false } | ConvertTo-Json

Invoke-WebRequest @params -Body $body -Credential $cred

Write-Host '  * Production status removed from Environment'


and I receive this

HTTP Error 500.0 - Internal Server Error
Internal Server ErrorMost likely causes:
IIS received the request; however, an internal error occurred during the processing o
f the request. The root cause of this error depends on which module handles the reque
st and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This
can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not
Things you can try:
Ensure that the NTFS permissions for the web.config file are correct and allow access
to the Web server’s machine account.
Check the event logs to see if any additional information was logged.
Verify the permissions for the DLL.
Install the .NET Extensibility feature if the request is mapped to a managed handler.

Create a tracing rule to track failed requests for this HTTP status code. For more in
formation about creating a tracing rule for failed requests, click here.
Detailed Error Information:
Module ManagedPipelineHandler
Notification ExecuteRequestHandler
Handler ExtensionlessUrlHandler-Integrated-4.0
Error Code 0x800703e9
Requested URL https://epicortask.grandrapidschair.com:443/EpicorTest10/api/v2/odata
Physical Path D:\Epicor\Websites\EpicorTest10\Server\api\v2\odata\GRC\Ice.LIB.Clien
Logon Method Anonymous
Logon User Anonymous
More Information:
This error means that there was a problem while processing the request. The request w
as received by the Web server, but during processing a fatal error occurred, causing
the 500 error.
View more information »
Microsoft Knowledge Base Articles:

I did do a Failed Request Trace but I do not see anything that stands out to me on why it fails.

Thanks for any assistance.

I don’t mean to $body shame, but if you dump the PowerShell $body variable and compare that to the input to Swagger or Postman, are they identical?

Is there anything related in server event viewer?

Swagger and Postman

“isProduction”: false

No, I have not seen anything in the Event Viewer for App Server, Task Agent or in the Windows Logs

And the $body variable of your script looks like?

$body = @{ ‘isProduction’ = $false } | ConvertTo-Json

I’m sorry, what is the VALUE of

$body = @{ ‘isProduction’ = $false } | ConvertTo-Json

at runtime?


Write-Host $body 

before the Invoke-WebRequest. Dump your $params as well.

Checked that out previously myself

the params is a collection

System.Collections.DictionaryEntry System.Collections.DictionaryEntry System.Collecti
ons.DictionaryEntry System.Collections.DictionaryEntry

the body
“isProduction”: false

Here is the Key Values of the $params collection

ContentType : application/json
Method : POST
Headers : System.Collections.DictionaryEntry System.Collections.DictionaryEntry
Uri : https://[URL]/EpicorTest10/api/v2/odata/GRC/Ice.LIB.C

I replaced our actural URL with [URL] in this post

OK. :thinking:

For giggles and expletives, have you considered using Invoke-RestMethod?

Example here: Invoke-RestMethod (Microsoft.PowerShell.Utility) - PowerShell | Microsoft Docs

Essentially, it’s the same thing really but maybe…

Thanks for the suggestion, I forgot about it actually, I tried that prior to using WebRequest for the Function calls and I had issues with it, can’t remember what it was but moving to WebRequest fixed the issue. Gave RestMethod a try and got the same error.


Are you using the entire domain in the [URL]? Your previous successful attempt shows:

Just a thought.

Another thought, check the IIS logs and compare the request from Swagger with the PowerShell request to rule out any differences in calling.

<your appserver location>\inetpub\logs\LogFiles