AWS & PoweShell - How do I go through a text file from within a script

How can I run Script 2 by it's self? Script 1 is a cmd file, but what do I need to delclare in Script 2 to make it a valid script?

Script 1 pulls out all the snapshots (their ID) for a volume to a text file (snaps.txt)
aws ec2 describe-snapshots --filters Name=volume-id,Values=vol-123456 --query Snapshots[*].{ID:SnapshotId} --output text >c:\temp\snaps.txt

Script 2 should go through the text file snaps.txt and tag all the snapshots.
for /F %i in (c:\temp\snaps.txt) do aws ec2 create-tags --resources %i --tags Key=Environment,Value=ABC123

I ran the file snapscript01.cmd to create the list of snapshots in a text file which worked. Awesome. What type of file do I need to run through that output file snaps.txt so it can loop it? I created a cmd and bat with just the command text and it didn't work. No error. I don't want to touch the existing backup script. I want a new script.
FikreDenekeAWS Cloud EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
Is that the complete Script1?  

What do the contents of snaps.txt look like (sensitive data replaced with something)
Shalom CarmelCTOCommented:
@echo off 


@call aws ec2 describe-snapshots --filters Name=volume-id,Values=%VOLUME% --query Snapshots[*].{ID:SnapshotId} --output text > %WORKFILE%

for /F %%i in (%WORKFILE%) do ( 
	echo tagging %%i.....
	@call aws ec2 create-tags --resources %%i --tags Key=Environment,Value=%ENVIRONMENT%

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
FikreDenekeAWS Cloud EngineerAuthor Commented:
Shalomc, thanks for your response. Did I properly give you credit by clicking the thumbs up? Let me ask you, what is the difference between your script and the one line script below that I recently found? I ran the script below with a cmd extension.

for /F %%i in (c:\temp\snapshots.txt) do aws ec2 create-tags --resources %%i --tags Key=Environment,Value=ABC123
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

FikreDenekeAWS Cloud EngineerAuthor Commented:
Dustin Saunders, it is a text file with one column with snapshot ids such as the examples below?

FikreDenekeAWS Cloud EngineerAuthor Commented:
1. Can we combine these two scripts? They work by themselves, but I can't combine successfully. I want to ideally get the latest snapshot, but any snapshots after 01-01-2018. The current method is grabbing all snapshots which exceed 20,000 and dumps it to a text file, but takes all day to apply the tag. All current snapshots have tags (still running) so I just need to tag most recent or anything after 01-01-2018.

aws ec2 describe-snapshots --filters Name=volume-id,Values=vol-7e82333f --query Snapshots[*].{ID:SnapshotId} --output text >>c:\\AWS\\all_HST-2_snapshots.txt

aws ec2 describe-snapshots --query 'Snapshots[?StartTime >= `2018-01-01`].{id:SnapshotId}'
Shalom CarmelCTOCommented:
Your original script had the wrong number of percent signs :D

I am not sure that I follow your last comment. How do you mean to combine the scripts?
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: shalomc (https:#a42429804)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Experts-Exchange Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.