I am looking to get a script working that can filter AWS instances according to the IAM role assigned to it and then get the private ip address of it. I had asked a similar question recently: filtering ec2 instances by associated IAM role with boto where the answer has worked wonderfully. Now, I would like to do the same thing except on Windows PowerShell.
I understand that PowerShell does not provide nice features as boto
does however I know that there is a AWS Tools Kit for PowerShell which you can use to get information on instances.
I have already setup a profile to run on all sessions.
PS > Set-AWSCredentials -AccessKey AKIAIOSFODNN7EXAMPLE -SecretKey wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY -StoreAs TestUser1
PS > Initialize-AWSDefaults -ProfileName TestUser1 -Region ap-southeast-2
This is roughly what my code looks like on boto where it filters instances by IAM role and then stores its private ip addresses in a list.
instancelist = conn.get_only_instances(filters={"iam-instance-profile.arn": "arn:aws:iam::123456789012:instance-profile/TestRole"})
aList = list()
for instance in instancelist:
output1 = instance.private_ip_address
aList.append(output1)
What would be the equivalent way to do so in PowerShell?