无法修改PS自定义对象中嵌套属性的值

时间:2016-06-22 19:07:32

标签: powershell pscustomobject

我有一个PS自定义对象:

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=}}

我可以轻松修改顶级属性的值,例如TourCode或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=}}

但在尝试修改SValues属性中的属性S1,S2,S4或S4时,我发现了一些奇怪的错误消息:

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

为什么说它找不到房产?我可以通过这样的方式轻松获得它的价值:

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

我做错了什么?

UPD:屏幕截图显示 gm -i $ testTournament.SValues 的输出:http://i.imgur.com/BeRr2aJ.png 屏幕截图为JSON片段:http://i.imgur.com/BBK2nsi.png(类似数据) 使用以下代码读取和转换JSON文件:

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

然后创建$ testTournament:

$testTournament = $testData.Tournaments | Get-Random

0 个答案:

没有答案
相关问题