Skip to content

Instantly share code, notes, and snippets.

@tylergohl
Created July 6, 2018 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylergohl/c5fcb5a68b2f44cf13dae8ec9951e0b0 to your computer and use it in GitHub Desktop.
Save tylergohl/c5fcb5a68b2f44cf13dae8ec9951e0b0 to your computer and use it in GitHub Desktop.
Runs a ec2 systems manager command
$NameWildcard = 'prd01worker*'
$Comment = 'Doing stuff'
$Commands = @(
'dir c:\users',
'dir c:\'
)
# Instance state code 16 is for powered on instances
$Instances = (Get-EC2Instance -Filter @( @{name='tag:Name'; values=$NameWildcard}; @{name='instance-state-code'; values = 16} ) | Select-Object -ExpandProperty instances).InstanceId
$runPSCommand = Send-SSMCommand -InstanceId $Instances -DocumentName AWS-RunPowerShellScript -Comment $Comment -Parameter @{'commands'=$Commands}
# Check Status and get output
Get-SSMCommandInvocation -CommandId $runPSCommand.CommandId -Details $true | select -ExpandProperty CommandPlugins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment