Skip to content

Instantly share code, notes, and snippets.

@bluPhy
Last active January 24, 2022 14:54
Show Gist options
  • Save bluPhy/e9dbe85ba6b4ae40c95c00d91e6757d1 to your computer and use it in GitHub Desktop.
Save bluPhy/e9dbe85ba6b4ae40c95c00d91e6757d1 to your computer and use it in GitHub Desktop.
AWS-Rename-Volumes-to-Match-Instance-Name.ps1
$Tab = [char]9
$Tag = New-Object Amazon.EC2.Model.Tag
foreach ($vol in (Get-EC2Volume)) {
$EBSVolId = $($vol.Attachments.VolumeId)
$EC2InstanceId = $($vol.Attachments.InstanceId)
$EC2InstanceName = ((Get-EC2Instance -InstanceId $EC2InstanceId).Instances.Tags | Where-Object { $_.Key -eq "Name" } | Select-Object -ExpandProperty Value)
Write-Host "Volumen Id:" $EBSVolId $Tab "Instance Id:" $EC2InstanceId $tab "Instance Name: " $EC2InstanceName
$Tag.Key = "Name"
$Tag.Value = "$EC2InstanceName-Disk"
Write-Host -NoNewline "Renaming $EBSVolId" $Tab ; $Tag
# New-EC2Tag -Resource $EBSVolId -Tag $Tag
Write-Host ""
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment