Last active
January 24, 2022 14:54
-
-
Save bluPhy/e9dbe85ba6b4ae40c95c00d91e6757d1 to your computer and use it in GitHub Desktop.
AWS-Rename-Volumes-to-Match-Instance-Name.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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