Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Rugby-Ball/b186b4cecfd743307ed9ff005a09ab70 to your computer and use it in GitHub Desktop.

Select an option

Save Rugby-Ball/b186b4cecfd743307ed9ff005a09ab70 to your computer and use it in GitHub Desktop.
Set Tag and Value to all running Windows EC2 #EC2 #AWS #Public #Maintenance #Windows #Utility
#set-ec2-tag-all-running-windows-instances.ps1
<#
Description: Set Tag and Value to all running Windows EC2
Written: Ed Walsh
PowerShell.Core tested: Yes
Version: 1.0.0
Create Date: 1/10/2022
Revised Date: 1/10/2022
#>
$instances = ((Get-EC2Instance -Region $Region).Instances | Where-Object {$_.Platform -eq "Windows" -and $_.state.name -eq 'running'} ).InstanceId
foreach ($i in $instances)
{
$tag = New-Object Amazon.EC2.Model.Tag
$tag.Key = "managed"
$tag.Value = "yes"
New-EC2Tag -Resource $i -Tag $tag
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment