I am pulling a JSON structure via Invoke-RestMethod. No errors and powershell objects are created, so the parsing is working.
I'm pulling an array of objects that will later be iterated through, but somehow a $null is getting inserted as the first object. I am using 'Null Conditional Assignment':
# https://stackoverflow.com/a/10642435
# Null Conditional Assignment
$x = $null
$x ??= 100 # $x is now 100
$x ??= 200 # $x remains 100
# Environment
PS /> $PSVersionTable
Name Value
---- -----
PSVersion 7.4.6
PSEdition Core
GitCommitId 7.4.6
OS Ubuntu 24.04 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
PS />
My snippet:
$meta = Invoke-RestMethod -Uri $Uri
$thisscript = $meta.scripts | Where-Object -Property scriptid -Match $scriptid
$clusters ??= $thisscript.config.ontap_clusters