vmware / PowerCLI-Example-Scripts

http://blogs.vmware.com/powercli
Other
746 stars 603 forks source link

PowerCLI module is broken in PS 7.2 due to a breaking change in Newtonsoft.Json v13.0.1 #494

Closed daxian-dbw closed 2 years ago

daxian-dbw commented 2 years ago

Steps to reproduce

PowerShell 7.2.0 (The error does not appear with PowerShell 7.0 LTS or with 7.1.5.) Install VMware PowerCLI Import Module: https://github.com/vmware/PowerCLI-Example-Scripts/blob/master/Modules/Backup-VCSA/**Backup-VCSA.psm1** Connect-CisServer Get-VCSABackupJobs

Expected behavior

Receive information from PowerCLI API.

The error does not appear with PowerShell 7.0 LTS or with 7.1.5.

Actual behavior

The reader's MaxDepth of 64 has been exceeded.

Error details

Get-CisService: 12.11.2021 17:19:49 Get-CisService  One or more errors occurred. (One or more errors occurred. (The reader's MaxDepth of 64 has been exceeded. Path
'result.output.STRUCTURE['com.vmware.vapi.metadata.metamodel.component_data'].info.STRUCTURE['com.vmware.vapi.metadata.metamodel.component_info'].packages[7].STRUCTURE.map-entry.value.STRUCTURE['com.vmware.vapi.metadata.metamodel.packa
ge_info'].services[0].STRUCTURE.map-entry.value.STRUCTURE['com.vmware.vapi.metadata.metamodel.service_info'].structures[6].STRUCTURE.map-entry.value.STRUCTURE['com.vmware.vapi.metadata.metamodel.structure_info'].fields[5].STRUCTURE['co
m.vmware.vapi.metadata.metamodel.field_info'].type.STRUCTURE['com.vmware.vapi.metadata.metamodel.type'].generic_instantiation.OPTIONAL.STRUCTURE['com.vmware.vapi.metadata.metamodel.generic_instantiation'].element_type.OPTIONAL.STRUCTUR
E['com.vmware.vapi.metadata.metamodel.type'].generic_instantiation.OPTIONAL.STRUCTURE['com.vmware.vapi.metadata.metamodel.generic_instantiation'].map_value_type.OPTIONAL.STRUCTURE['com.vmware.vapi.metadata.metamodel.type'].generic_inst
antiation.OPTIONAL.STRUCTURE['com.vmware.vapi.metadata.metamodel.generic_instantiation'].map_value_type.OPTIONAL.STRUCTURE['com.vmware.vapi.metadata.metamodel.type'].generic_instantiation.OPTIONAL.STRUCTURE['com.vmware.vapi.metadata.me
tamodel.generic_instantiation'].element_type', line 1, position 567214.))

Get-CisService: 12.11.2021 17:19:49 Get-CisService  CisService with name 'com.vmware.appliance.recovery.backup.job' was not found using the specified filter(s). 

Write-Error: Cannot bind argument to parameter 'Exception' because it is null.

Environment data

Debian 10 amd64

PS /usr/lib/zabbix/externalscripts> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.0
PSEdition                      Core
GitCommitId                    7.2.0
OS                             Linux 4.19.0-16-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
daxian-dbw commented 2 years ago

Quoted from: https://stackoverflow.com/a/68580426:

In Json.NET 13.0.1, Newtonsoft changed the default MaxDepth for JsonReader (and hence all derived reader types including JsonTextReader) to 64:

Change - JsonReader and JsonSerializer MaxDepth defaults to 64

The ConvertFrom-Json command in PowerShell already specified the MaxDepth in JsonSerializerSettings, so it should not be affected. Therefore, it's likely that the PowerCLI module is directly calling APIs from Newtonsoft.Json.dll, and should be updated accordingly. @xenadmin can you please open an issue in https://github.com/vmware/PowerCLI-Example-Scripts about this?

https://github.com/PowerShell/PowerShell/blob/7dc4587014bfa22919c933607bf564f0ba53db2e/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/JsonObject.cs#L179-L187

xenadmin commented 2 years ago

Additionally I opened an official VMware support request (21277890011) as per: https://blogs.vmware.com/PowerCLI/2017/08/powercli-support-breakdown.html

Alta2048 commented 2 years ago

Hi @xenadmin , thanks for reporting this . Do you know if VMware Support provided you with an Update/ETA on this issue ? It also affect function Get-CisService

xenadmin commented 2 years ago

I got a phone call from VMware the next day, where they acknowledged the issue, informed me that they will immediately close the case, as this will be tracked here in this Github issue, and told me to watch out for newer releases of PowerCLI. To workaround this this issue, I had to downgrade to PowerShell LTS in the meantime.

kamennikolov commented 2 years ago

I can confirm that we're aware of the issue and we're working to address it in the next PowerCLI version.

mcarpendale commented 2 years ago

@kamennikolov - can you please share the workaround until the new version of PowerCLI is released?

kamennikolov commented 2 years ago

Currently the only workaround is to use an older PowerShell version - 7.0 or 7.1. Another workaround would be to refactor this module to use the new SDK modules, instead of Get-CisService for accessing the API.

xenadmin commented 2 years ago

@mcarpendale In my use-case, I have Debian (10) VMs, with powershell and powercli, where my scripts fail. On Debian I had to downgrade to powershell-lts to make everything work again, which looks like this as of today: grafik

mcarpendale commented 2 years ago

thanks @kamennikolov and @xenadmin - 7.1.5 is working from me again

MallocArray commented 2 years ago

Confirmed still not working with Powershell 7.2.1 and PowerCLI 12.4.1 Using Windows Powershell 5.1 is fine

abidlen commented 2 years ago

PowerCLI 12.5 resolved the issue on Powershell 7.2.1 for me https://vdc-download.vmware.com/vmwb-repository/dcr-public/02623a82-abc4-421c-a788-87578bd66208/5ac43430-05f3-489e-af9c-c8de75b65de7/vmware-powercli-125-release-notes.html