PowerShell challenge
One liner to filter and present a data
Get data from AWS, filter it, then present a subset of returned data one of which includes a specific tag key. The challenging part? Do it as a single command. There'll be lots of pipes and pipeline variables.1 2 3 4 5 6 7 | get-ec2NetworkInterface | ?{$_.vpcid -like "vpc-12345"} | select privateipaddress, description, tagset | format-table privateipaddress, description, @{Label="Name"; Expression = {($_.tagset | ?{$_.key -eq "Name"}).value}} |
Explanation:
Line 1: AWS PowerShell command to return all nic in an account
Line 2: Filter the previous output to only include this one VPC
Line 3: Filter the previous output to only show these three properties
Line 4: Filter the previous out in a table to include...
Line 5: privateipaddress
Line 6: description
Line 7: We can use hash table with two keys Label and Expression that format-table will use. In the expression, the first pipeline variable ($_.tagset) is from line 3 and the second pipeline variable ($_.key) is from $_.tagset.
No comments:
Post a Comment