I am querying the ResourceRecordSets in an AWS Route53 zone. I am trying to transform the name of the properties with select-object.
There are two records in the records sets. One has two items in the ResourceRecords the other has one item in ResourceRecords.
PS> (Get-R53ResourceRecordSet -HostedZoneId $zone.Id -MaxItem 1000).ResourceRecordSets
Name : simple.my-domain.com.
Type : A
SetIdentifier :
Weight : 0
Region :
GeoLocation :
Failover :
MultiValueAnswer : False
TTL : 300
ResourceRecords : {Amazon.Route53.Model.ResourceRecord, Amazon.Route53.Model.ResourceRecord}
AliasTarget :
HealthCheckId :
TrafficPolicyInstanceId :
CidrRoutingConfig :
GeoProximityLocation :
Name : weighted.my-domain.com.
Type : A
SetIdentifier : my record id
Weight : 0
Region :
GeoLocation :
Failover :
MultiValueAnswer : False
TTL : 300
ResourceRecords : {Amazon.Route53.Model.ResourceRecord}
AliasTarget :
HealthCheckId :
TrafficPolicyInstanceId :
CidrRoutingConfig :
GeoProximityLocation :
Each Amazon.Route53.Model.ResourceRecord is an object with a single property named Value.
PS> (Get-R53ResourceRecordSet -HostedZoneId $zone.Id -MaxItem 1000).ResourceRecordSets[0].ResourceRecords | Get-Member
TypeName: Amazon.Route53.Model.ResourceRecord
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Value Property string Value {get;set;}
I want to rename ResourceRecords to resource_records and Value to value. To simplify and troubleshoot I am trying just to convert ResourceRecords to resource_records
PS> (Get-R53ResourceRecordSet -HostedZoneId $zone.Id -MaxItem 1000).ResourceRecordSets | Select-Object Name, Type, Weight, MultiValueAnswer, @{N='resource_records';E={$_.ResourceRecords}}
Name : simple.my-domain.com.
Type : A
Weight : 0
MultiValueAnswer : False
resource_records : {Amazon.Route53.Model.ResourceRecord, Amazon.Route53.Model.ResourceRecord}
Name : weighted.my-domain.com.
Type : A
Weight : 0
MultiValueAnswer : False
resource_records : Amazon.Route53.Model.ResourceRecord
But, it seems to convert the single item object array into an object. {Amazon.Route53.Model.ResourceRecord} has become Amazon.Route53.Model.ResourceRecord.
I have tried numerous ideas to try to prevent this from happening, and if it doesn't flat out fail it still always produces the same output.
For instance, I have tried casting it to an array:
PS> (Get-R53ResourceRecordSet -HostedZoneId $zone.Id -MaxItem 1000).ResourceRecordSets | Select-Object Name, Type, Weight, MultiValueAnswer, @{N='resource_records';E={@($_.ResourceRecords)}}
But, this doesn't make any difference.
Is there any way to prevent this from being converted into a non-array?