我的powershell数组出了什么问题? [英] What is wrong with my powershell array?

查看:83
本文介绍了我的powershell数组出了什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$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





好​​我为什么选择在实例ID的输出上没有得到返回的instanceID?



我尝试过:



我试图将AMI Name标记放入一个数组中,然后为每个标记执行一个为每个EC2实例创建关联的AMI。



任何人都可以帮助它似乎在instanceID上没有输出错误,即使我写了Write-Host $ 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

推荐答案

Servers = Get-EC2Tag -Region us-east-2 | ? {
Servers = Get-EC2Tag -Region us-east-2 | ? {


_。资源类型-eq实例 - 和
_.ResourceType -eq "Instance" -and


_。键-eq名称} | select -expand Value
_.Key -eq "Name" } | select -expand Value


这篇关于我的powershell数组出了什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆