powershell script to check contents of a file for a string at the end of a line

We are running a script to check for the existence of config files in a whole series of folders.

When it finds the files it needs to check the content for the files and determine if a line ends with a specific string.

We have the script working but cannot see how to script the string check for the end of the line.  The string in question may appear with other text at the end of the line but we are only interested if there is an entry that ends with the particular string.


Regards


Spencer
vodyanoiAsked:
Who is Participating?

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

x
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.

Jeremy WeisingerSenior Network Consultant / EngineerCommented:
Search-String should get you what you want I think:
https://technet.microsoft.com/en-us/library/hh849903.aspx
Joseph DalyCommented:
If the data is always in the last line of the file you could do something like this.

get-content filename.config | select-string -pattern "xxxxxxxxx" | select -last 1
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
If you need the lines ending exactly with the pattern abcde, you can indeed use Select-String:
Get-Content file.config | select-string 'abcde$'

Open in new window

If you need only to know whether there are lines, add -Quiet to get only $false or $true instead of MatchInfo objects for each match.

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
aikimarkCommented:
What do you need to happen when such a line is found in these files?
vodyanoiAuthor Commented:
This works perfectly.  Added to the script and we get exactly what we need.  Must remember that regex is my friend.
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
Powershell

From novice to tech pro — start learning today.