1 Antwort
- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
1
The example you provided is lacking a command New-EC2Tag
to add a tag to an elastic IP allocation. Additionally, you are not using the right filter to get IPs with a tag (Name:TBA). Please see the below for a sample script. You can customize it as needed.
# set regions
$regions = @("eu-west-1", "us-west-2")
# AWS PowerShell documentation https://docs.aws.amazon.com/powershell/latest/reference/
foreach ($region in $regions) {
# https://docs.aws.amazon.com/powershell/latest/reference/items/Get-EC2Address.html
# Extracting elastic IP allocation IDs
$allocationIds = Get-EC2Address -Region $region | ForEach-Object { $_.AllocationId }
# Prepare a Tag to Add
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "Name"
$tag.Value = "TBA"
# Tag all the elasticIPs
try {
# https://docs.aws.amazon.com/powershell/latest/reference/items/New-EC2Tag.html
# add a new tag
New-EC2Tag -Resource $allocationIds -Tag $tag
} catch {
# Failed to add a tag
Write-Error $_.ErrorDetails
throw
}
# if tagging is successful, get IPs again
Get-EC2Address -Filter @{Name="tag:Name";Values="TBA"}
}
beantwortet vor 2 Jahren
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 6 Monaten
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 3 Jahren
thank you for your answer, really appreciate it