![]() You specify it as always, even if it’s an array of hash tables. But in this case, PowerShell is consistent, if cryptic. As we all know, assumptions in tech are usually wrong. ![]() Never having done this before, I assumed that creating an array of hash tables is done exactly like any other array. This meant I needed to pass more than one hash table to Get-EC2Instance. In my case it was simple: I needed to filter on the tag “Name” and on the attribute instance-state-code. Check out all the cool things you can filter using. The solution is to create an array of hash tables, specifying enough attributes to when calling Get-EC2Instance to enable the cmdlet to uniquely identify the desired instance. Thus, you need a way to supply multiple attributes of an instance using . In this case, we want a running instance with a specific string value in a tag called “Name”. You just check the box next to the one you want, which serves to tell the console which instance to use as the source for the AMI. But doing the same thing in PowerShell means you must uniquely identify the instance programmatically. In the console, it’s no problem to create an AMI of a running instance by using its name tag, even if a terminated instance has the same name tag. ![]() But it still makes for a lot of work for PowerShell script writers. I understand this, of course, since AWS cannot ensure tags are unique. But in PowerShell, you have to use unique identifiers to manage assets. When you are in the AWS Console, you work with names - at a logical level. I also don’t like the fact that AWS PowerShell cmdlets for managing assets do not use tags. This MSDN article delivers an excellent explanation of PowerShell hash tables. They are so much simpler to think of as a simple database of keys and their associated values. I am, however, slowly warming to PowerShell hash tables. Whatever that stuff is, topping it with an egg doesn’t make it any more delectable, IMO.
0 Comments
Leave a Reply. |