I am using the Powershell ISE for the below snippets.
Below ist the output format of the following command:
aws ec2 --profile $profile --region $region describe-instances --query "Reservations[*].Instances[*].[InstanceId,LaunchTime,State]"
[
[
[
"i-abc0123456789",
"2023-07-17T04:00:18+00:00",
{
"Code": 8,
"Name": "running"
}
]
],
[
[
"i-xyz9876543210",
"2023-07-17T04:00:16+00:00",
{
"Code": 16,
"Name": "running"
}
]
]
]
I have taken the help from this community to iterate the above input json stream in the below way as my lack of knowledge on this part, but I am now not able to see any value as an output of it i.e.
Write-Output ("instanceid :"+$a)
$objects = aws ec2 --profile $awsProfile --region $awsRegion describe-instances --query "Reservations[*].Instances[*].[InstanceId,LaunchTime,State]" | ConvertFrom-Json
$objects | ForEach-Object {
# Construct and implicitly output a [pscustomobject]
# instance from the elements of each nested array.
$a = [pscustomobject] @{
instanceid = $_[0][0]
launchdateb = [datetimeoffset] $_[0][1]
code = $_[0][2].Code
name = $_[0][2].Name
}
Write-Output ("instanceid :"+$a)
}
- Is this the way or any other comprehend way if I can iterate through the aws-cli objects of describe-instances
- And while doing the looping/iterating - how do I compare the Launchdate with any other date separately ?