'get-ec2volume not attach state blank
i got ebsvolumes in not attached state. When i run powershell script I want to populate the blank columns. but not working. please see below
import-module AWS.Tools.Common
$results = @()
$Volumes = get-ec2volume
$EC2instanceIds = $VolumeType.Attachments.InstanceId
foreach ($vol in $volumes) {
$result = "" | select EC2InstanceName, Device, InstanceId, volumeId, AvailabilityZone, CreateTime, Encrypted, Iops, Size, VolumeType, InstanceState
$result.EC2InstanceName = (((Get-EC2Instance -InstanceId ($vol.Attachments.InstanceId)) | Select-Object -ExpandProperty instances).Tags | ? {$_.key -eq "Name"}).value
$result.Device = $vol.Attachments.Device
$result.InstanceId = $vol.Attachments.InstanceId
$result.volumeId = $vol.volumeId
$result.AvailabilityZone = $vol.AvailabilityZone
$result.Encrypted = $vol.Encrypted
$result.CreateTime = $vol.CreateTime
$result.Iops = $vol.Iops
$result.Size = $vol.Size
$result.VolumeType = $vol.VolumeType
$result.InstanceState = $vol.Attachments.State
if ($vol.Attachments.State -eq "$null") -or ($vol.Attachments.Device -eq "$null") -or ($vol.InstanceId -eq "$null"))
{
$result.EC2InstanceName = "No Instance Attached"
$result.Device = "No Device Attached"
$result.InstanceId = "No Instance Attached"
$result.InstanceState = "Not Attached to any instance"
}
$results += $result
}
$results | export-csv -Notypeinformation -Useculture ebs_volume.csv
any idea?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|