Created
July 6, 2018 13:23
-
-
Save tylergohl/c5fcb5a68b2f44cf13dae8ec9951e0b0 to your computer and use it in GitHub Desktop.
Runs a ec2 systems manager command
This file contains 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
$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