【问题标题】:AWS powershell get volumes - attachment instanceidAWS powershell 获取卷 - 附件 instanceid
【发布时间】:2018-08-21 04:15:54
【问题描述】:

我试图通过 powershell 列出所有 AWS 卷并获取它所连接的实例。我正在运行一个具有帐户 root 权限的 powershell 程序,如下所示。

使用文档:
一种。 https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/EC2/TVolume.html
湾。 https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/EC2/TVolumeAttachment.html
我正在使用代码:

$volno=0
foreach ($i in Get-EC2Volume) { 
    ++$volno
    write-host $i.VolumeId $i.Name $i.Size $i.VolumeType
    write-host $i.Atachments.Count
    foreach ($j in $i.Atachments) {
      $j.InstanceId
    }
  }

我得到了这些结果:

vol-83d1e111  10 gp2
0
vol-2248a222  8 gp2
0
vol-4b48a333  30 gp2
0
vol-345fbf44  50 gp2
0
vol-b4876b55  8 gp2
0
....

问题

  1. 结果显示没有附件,也就是说,所有卷都没有附加到任何实例。一些卷附加到正在运行的实例。为什么?
    参考 A.显示有一个属性“附件”,其类型为System.Collections.Generic.List

    参考 B.表明Amazon.EC2.Model.VolumeAttachmentInstanceId 的成员

【问题讨论】:

    标签: amazon-web-services volumes


    【解决方案1】:

    对不起,我没有注意到一个错字:
    写主机 $i.Atachments.Count
    应该是
    写主机 $i.Attachments.Count



    foreach ($j in $i.Atachments) {
    应该是
    foreach ($j in $i.Attachments) {

    【讨论】:

      猜你喜欢
      • 2020-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-28
      • 1970-01-01
      • 1970-01-01
      • 2017-08-09
      • 2019-05-11
      相关资源
      最近更新 更多