0

I'm trying to extract an IP address from the output of AWS CLI command "describe-tags". I'm very new to Powershell and have been struggling. This is the output of the AWS command in both "text" and "json" formats.

If you can help me extract just the IP address from either of these formats, I'd greatly appreciate it. I'm using "Powershell 2" and ConvertFrom-JSon isn't available in this version. Let's just assume I can't upgrade to Powershell 3.

TEXT:

TAGS    nameserver      i-xxxxxxxx      instance        10.0.0.56

JSON:

{
    "Tags": [
        {
            "ResourceType": "instance",
            "ResourceId": "i-xxxxxxxx",
            "Value": "10.0.0.56",
            "Key": "nameserver"
        }
    ]
}

Thanks a lot!

Anthony Neace
  • 25,013
  • 7
  • 114
  • 129
urover
  • 470
  • 1
  • 5
  • 17

2 Answers2

1

you could use a regex, for example :

[regex]::match($awsoutput,"\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b").Value 
Loïc MICHEL
  • 24,935
  • 9
  • 74
  • 103
0

I wouldn't use regex here. Whenever I'm stuck on an older PS version without support for a feature I want, I look to see if someone has scripted the equivalent feature.

See here for an example: PowerShell 2.0 ConvertFrom-Json and ConvertTo-Json implementation

Robert Overmyer
  • 182
  • 1
  • 1
  • 8