Unable to modify value of a nested property in PS custom object

匆匆过客 提交于 2019-12-23 01:46:16

问题


I have a PS custom object:

TourCode           : s
TournamentNumber   : 524
TournamentName     : Mitsubishi Electric Championship at Hualalai
EnvironmentType    : PGA Tour
TournamentRootPath : /mitsubishi-electric-championship-at-hualalai
SValues            : {@{S1=championstour; S2=tournaments; S3=mitsubishi-electric-championship-at; S4=}}

I can easily modify values of the top level properties like TourCode or TournamentName:

PS C:\Users\yuriy> $testTournament.TourCode = 'r'

PS C:\Users\yuriy> $testTournament

TourCode           : r
TournamentNumber   : 524
TournamentName     : Mitsubishi Electric Championship at Hualalai
EnvironmentType    : PGA Tour
TournamentRootPath : /mitsubishi-electric-championship-at-hualalai
SValues            : {@{S1=championstour; S2=tournaments; S3=mitsubishi-electric-championship-at; S4=}}

But I'm stuck getting strange error message when trying to modify properties S1, S2, S4, or S4 within SValues property:

PS C:\Users\yuriy> $testTournament.SValues.S3 = 'newvalue'
The property 'S3' cannot be found on this object. Verify that the property exists and can be set.
At line:1 char:1
+ $testTournament.SValues.S3 = 'newvalue'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException

Why is it saying it cannot find the property? I can get its value easily by referring to it like this:

PS C:\Users\yuriy> $testTournament.SValues.S3
mitsubishi-electric-championship-at

What am I doing wrong?

UPD: Output of gm -i $testTournament.SValues is on screenshot: http://i.imgur.com/BeRr2aJ.png JSON fragment is on screenshot: http://i.imgur.com/BBK2nsi.png (similar data) The JSON file is read and converted using this code:

$testData = Get-Content -Raw -Path "Test Data.json" | ConvertFrom-Json

Then $testTournament is created:

$testTournament = $testData.Tournaments | Get-Random

来源:https://stackoverflow.com/questions/37976372/unable-to-modify-value-of-a-nested-property-in-ps-custom-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!