Click here to Skip to main content
15,879,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
$Servers = Get-EC2Tag -Region us-east-2 | ? { $_.ResourceType -eq "Instance" -and $_.Key -eq "Name" } | select -expand Value 
$a =@("$Servers,") # Name of servers to be restarted


ForEach($Servers in $a) {

 
    $instanceID = Get-EC2Instance -Region us-east-2 -Filter @{name='tag:Name'; values=$Servers} | Select -ExpandProperty instances | Select -expand InstanceId #Get instance ID

    }
    $instanceID


Okay why do I get no returned instanceID on the output of instance ID?

What I have tried:

I have attempted to put the AMI Name tag into an array then do a for each to create the associated AMI for every EC2 Instance.

Can anyone help it seems to error on instanceID with no output even if I do Write-Host $instanceID
Posted
Updated 25-Sep-18 23:37pm
v4
Comments
Richard MacCutchan 28-Aug-18 5:21am    
"it seems to error on the line New-EC2Image"
Please edit your question and be more specific about the problem.

1 solution

The first line returns an array of servers (unless theres only 1)
You are making a 1 element array, containing your array of servers in $a
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900