I am writing a script where Block Devices attached to a EC2 instance are matched and then a corresponding tag is set.
I have following PSOObject and visualization in the console
New-Object PSObject -Property @{
Disk = $Disk;
Partitions = $Partitions;
DriveLetter = If ($DriveLetter -eq $null) { "N/A" } Else { $DriveLetter };
EbsVolumeId = If ($EbsVolumeID -eq $null) { "N/A" } Else { $EbsVolumeID };
Device = If ($BlockDeviceName -eq $null) { "N/A" } Else { $BlockDeviceName };
VirtualDevice = If ($VirtualDevice -eq $null) { "N/A" } Else { $VirtualDevice };
VolumeName = If ($VolumeName -eq $null) { "N/A" } Else { $VolumeName };
}
} | Sort-Object Disk | Format-Table -AutoSize -Property Disk, Partitions, DriveLetter, EbsVolumeId, Device, VirtualDevice, VolumeName
Now I have following simple New-EC2tag command tagging the instance.
New-EC2Tag -Resource $InstanceId -Tags @{ Key = $DriveLetter; Value = $BlockDeviceName}
Basically it just writes the C: Drive and I believe I have to iterate through the PSObject to basically also set the corresponding drives.
I would bge grateful for any help.