KelvinTegelaar / AutotaskAPI

Autotask 2020.2 REST API PowerShell wrapper
https://cyberdrain.com
MIT License
67 stars 25 forks source link

[BUG] No support for Powershell 7.0 #20

Closed karstenbakker closed 4 years ago

karstenbakker commented 4 years ago

Describe the bug Cannot get the plugin working on Powershell 7.0 so I can't use it in Azure functions. I keep getting no

`Retrieving webservices URI based on username
Setting AutotaskBaseURI to https://webservices4.autotask.net/ATServicesRest/ using version V1.0
Setting API resource parameters. This may take a moment.

InvalidOperation: C:\..\..\PowerShell\Modules\AutoTaskAPI\1.0.2\AutoTaskAPI.psm1:232:13
Line |
 232 |              $streamReader = [System.IO.StreamReader]::new($_.Exceptio …
     |              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Method invocation failed because [System.Net.Http.HttpResponseMessage] does not contain a method named 'GetResponseStream'.`

To Reproduce Steps to reproduce the behavior:

  1. Have 7.0 installed.
  2. Run Install-Module AutoTaskAPI in 7.0 shell
  3. Try to perform a command.

Expected behavior Expect it to work with 7.0, I did try to fix it by removing the getresponsestream from the psm file. By just adding $_.Exception_Message this seems to work. image

It looks like the getresponsestream isn't supported anymore in 7.0.

Desktop (please complete the following information):

KelvinTegelaar commented 4 years ago

Unfortunately that creates a bit of a pickle, the error code handling of REST calls ain't all the nice with invoke-restmethod.

I'll research a Posh7 compatible way to do get the same results

KelvinTegelaar commented 4 years ago

I've added a fix by only triggering the advanced error logs when the PowerShell version is less than 6. This fixes this issue for both Core and 7.0.

This version has also pushed to the PSGallery.