Amazon web services 无法从powershell获取存在ec2实例的映像ID
我正在尝试获取spowershell脚本,以便能够提取存在ec2实例的映像id 比如:Amazon web services 无法从powershell获取存在ec2实例的映像ID,amazon-web-services,powershell,Amazon Web Services,Powershell,我正在尝试获取spowershell脚本,以便能够提取存在ec2实例的映像id 比如: Write Host-BackgroundColor白色-ForegroundColor蓝色“实例的ID是什么” $tid=读取主机“实例ID” 写入主机-背景色白色-背景色蓝色“输入实例所在的区域” $tregion=读取主机“区域” $Tinstancetype=((Get-EC2Instance-InstanceId$tid).instances)。InstanceType 写入主机“实例类型:$Tin
Write Host-BackgroundColor白色-ForegroundColor蓝色“实例的ID是什么”
$tid=读取主机“实例ID”
写入主机-背景色白色-背景色蓝色“输入实例所在的区域”
$tregion=读取主机“区域”
$Tinstancetype=((Get-EC2Instance-InstanceId$tid).instances)。InstanceType
写入主机“实例类型:$Tinstancetype”
就像上面这段代码一样,我输入了实例id,它会溢出实例类型。
我需要可以溢出图像ID的代码。您只请求实例类型属性。
Get-EC2Instance
将返回一个对象数组,每个对象都有许多属性。您的命令仅显示属性“InstanceType”的值
如果运行(Get-EC2Instance-InstanceId$tid)。实例|选择*
,您将看到所有属性及其值,其中一个属性将是图像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"
您可以用同样的方法检索ImageId。太棒了。它起作用了。只是想知道一件事,因为(Get-EC2Instance-InstanceId$tid)没有给出任何关于图像id的输出,但是当我们尝试使用“.imageID”获取输出时,它确实给出了图像id。奇怪但工作正常。。谢谢。你能把你得到的结果贴出来吗?您是否使用过
(Get-EC2Instance-InstanceId$tid)。实例|选择*
?Select*是别名和位置参数,完整上下文为Select Object-Property*
。它将覆盖任何模板化输出并显示所有属性和值。我目前没有访问带有EC2实例的AWS帐户来测试输出。是的,在我添加select*后,它将为我提供所有参数。。谢谢你澄清这件事。。。