I am working with AWS's PowerShell cmdlets to manage Amazon Machine Images (AMI). The script below works well to produce a grid view the user can search and sort. I just want to enhance the UI a little by showing specific tags in place of the hash tables for the object properties 'Tag' and 'BlockDeviceMapping'.
'Expand-Properties' doesn't do the trick and I just can't seem to find an example of how to use 'Select-Object' to create output objects that have a mixture of both string properties (in this case) as well as selected values from properties that are hash tables.
Appreciate all suggestions.
Get-EC2Image -Owner self | Select-Object -Property Imageid, Name, Description, CreationDate, Tag, BlockDeviceMapping | Out-GridView -PassThru |
# Code to manage deleting AMIs and their associated snapshots
So the problem is that Out-GridView can't deal with hierarchical data. That's very likely what it's being fed, and there's no way you can really change that, unless you take one of those "sub tables" (if I'm understanding the problem) and just munge them into a flat string.
Yeah, so, probably Join-String or the -join operator. I mean, there's no pretty or perfect way to do this, so you kind of have to decide what you'd be happy with. You might even just be happy piping the sub-hash table to Out-String and letting it do its thing, and then using the result. But you might end up needing to reconstruct the object. Like, get your output, but don't send that to Out-GridView. Instead, construct a new object, copy what properties you want and munge them in the process, and then GridView that.