I've been trying to construct a simple output from an AWS Route53 query in PowerShell that would have Name, Type and Values. However, the values are stored as ResourceRecords and I cannot manage to get them to show up properly, after hours of trying.
Here's a bit of code to show what I mean:
PS> $(Get-R53ResourceRecordSet -HostedZoneId "/hostedzone/xxx").ResourceRecordSets | Select Name,Type,ResourceRecords
Name Type ResourceRecords
---- ---- ---------------
nodepoint.ca. A {Amazon.Route53.Model.ResourceRecord}
nodepoint.ca. MX {Amazon.Route53.Model.ResourceRecord}
nodepoint.ca. NS {Amazon.Route53.Model.ResourceRecord...
nodepoint.ca. SOA {Amazon.Route53.Model.ResourceRecord}
As you can see the last column isn't expanded. This returns the last column:
PS> $cmd | Where {$_.Type -eq "NS"} | Select ResourceRecords
While this returns the proper records:
PS> $cmd | Where {$_.Type -eq "NS"} | Select -ExpandProperty ResourceRecords
I just can't manage to get that last column to display those values. I've tried:
PS> $(Get-R53ResourceRecordSet -HostedZoneId "/hostedzone/xxx").ResourceRecordSets | Select Name,Type,@{Name='Value';Expression={$_.ResourceRecords | Select -ExpandProperty ResourceRecord}}
PS> $(Get-R53ResourceRecordSet -HostedZoneId "/hostedzone/xxx").ResourceRecordSets | Select Name,Type,@{Name='Value';Expression={$_.ResourceRecords | Select -ExpandProperty ResourceRecord -Replace "`n"," "}}
PS> $(Get-R53ResourceRecordSet -HostedZoneId "/hostedzone/xxx").ResourceRecordSets | Select Name,Type,@{Name='Values';Expression={$_.ResourceRecords | Select -ExpandProperty ResourceRecords | Out-String}}
None of which work, they all show an empty third column. The only way I made it work is to manually write each value with a foreach:
PS> $(Get-R53ResourceRecordSet -HostedZoneId "/hostedzone/Z1W5966G1TGW7S").ResourceRecordSets | foreach { $_.Name; $_.Type; $_ | Select -ExpandProperty ResourceRecords}
But I want to keep it in columns, with the last column showing each record with a space in between. I don't know where to go from here.
Aucun commentaire:
Enregistrer un commentaire