0

I'm working on an AWS Powershell script to return the custom tag value for the instance on which the script is run. The tag is "itowner" and the value would be an email address. This is my code, the first line works and returns the instanceId but I can't quite get the second line to work.

(Invoke-WebRequest -usebasicparsing -Uri 'http://169.254.169.254/latest/meta-data/instance-id').content
for ($instanceId in $instanceId.content Get-EC2Tag -Filter @{Name="key";Value="itowner"})
TIM02144
  • 593
  • 1
  • 4
  • 17

1 Answers1

0

Try this:

$i = (Invoke-WebRequest -usebasicparsing -Uri 'http://169.254.169.254/latest/meta-data/instance-id').content
(Get-EC2Tag -Filter @(@{Name="resource-id";Value=$i},@{Name="key";Value="itowner"})).Value  

Since you are pulling this from the instance metadata, you should get a single instance id and thus don't need the loop. However, you do need to add the InstanceId to the filter.