1. copy the instance id from aws console to file
2. remove the , from file
sed -i 's/,//g' file
3. get ip address list to file2
$ cat getip.sh #!/bin/bash for id in `cat file` do #echo $id >> file2 aws ec2 describe-instances --instance-ids $id | grep PrivateIpAddress | head -1 | awk -F ":" '{print $2}' | sed 's/[",]//g' >> file2 done
4. copy file2 to host.txt,
5. create inssm.bat
@echo off net use x: \10.xx.xx.241Share /user:joinad password x: REM “Replace your codes starts from here” Ec2Install.exe /sp- /silent /norestart REM “replace your codes end of here.” if %ERRORLEVEL% NEQ 0 goto failed echo "SSM agent updated DONE!" cd .. echo %computername% %date% %time% >> ComputerList.txt echo "Updating of SSM agent succeeded. " goto end :faile echo $%computername% %date% %time% >> ComputerList.txt echo "Updating of SSM agent failed. " :end c: net use x: /delete
6. run inssm.bat script to remote host via psexec
for /F "tokens=*" %%A in (host.txt) do C:PSToolsPsExec.exe \%%A -u admin -p "pwd" -c -w c:/ "C:inssm.bat"