[英]Not able to get Image ID of existence ec2 instance from powershell
我正在尝试获取 spowershell 脚本,以便我可以提取存在 ec2 实例的图像 ID。
喜欢 :
Write-Host -BackgroundColor White -ForegroundColor Blue "What is the ID of the instance"
$tid=Read-Host "Instance ID"
Write-Host -BackgroundColor White -ForegroundColor Blue "Input the region the instance inhabits"
$tregion=Read-Host "Region"
$Tinstancetype = ((Get-EC2Instance -InstanceId $tid).instances).InstanceType
Write-Host "Instance Type : $Tinstancetype"
就像在上面的这段代码中一样,我输入了 Instance id 并且它溢出了实例类型。 我需要可以溢出图像 ID 的代码。
您只是请求 Instance Type 属性。 Get-EC2Instance
会带回一个对象数组,每个对象都有多个属性。 您的命令仅显示属性“InstanceType”的值
如果您运行(Get-EC2Instance -InstanceId $tid).instances | Select *
(Get-EC2Instance -InstanceId $tid).instances | Select *
您将看到所有属性及其值,这些属性之一将是图像 ID。
Get-EC2Instance
输出示例:
C:\> (Get-EC2Instance -InstanceId i-12345678).Instances
AmiLaunchIndex : 0
Architecture : x86_64
BlockDeviceMappings : {/dev/sda1}
ClientToken : TleEy1448154045270
EbsOptimized : False
Hypervisor : xen
IamInstanceProfile : Amazon.EC2.Model.IamInstanceProfile
ImageId : ami-12345678
InstanceId : i-12345678
InstanceLifecycle :
InstanceType : t2.micro
KernelId :
KeyName : my-key-pair
LaunchTime : 12/4/2015 4:44:40 PM
Monitoring : Amazon.EC2.Model.Monitoring
NetworkInterfaces : {ip-10-0-2-172.us-west-2.compute.internal}
Placement : Amazon.EC2.Model.Placement
Platform : Windows
PrivateDnsName : ip-10-0-2-172.us-west-2.compute.internal
PrivateIpAddress : 10.0.2.172
ProductCodes : {}
PublicDnsName :
PublicIpAddress :
RamdiskId :
RootDeviceName : /dev/sda1
RootDeviceType : ebs
SecurityGroups : {default}
SourceDestCheck : True
SpotInstanceRequestId :
SriovNetSupport :
State : Amazon.EC2.Model.InstanceState
StateReason :
StateTransitionReason :
SubnetId : subnet-12345678
Tags : {Name}
VirtualizationType : hvm
VpcId : vpc-12345678
您的脚本将如下所示:
Write-Host -BackgroundColor White -ForegroundColor Blue "What is the ID of the instance"
$tid=Read-Host "Instance ID"
Write-Host -BackgroundColor White -ForegroundColor Blue "Input the region the instance inhabits"
$tregion=Read-Host "Region"
$Instance = ((Get-EC2Instance -InstanceId $tid).instances)
$Tinstancetype = $Instance.InstanceType
$ImageID =$Instance.ImageId
Write-Host "Instance Type : $Tinstancetype"
Write-Host "Instance Type : $ImageID"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.