How can I use Powershell to remove dupliation within a file?

I am currently working with this script.

I need to convert this script to a Powershell script.
It looks within a file for duplication, and if there is duplication it deletes the duplication.


setlocal

REM Defile file location
set File1=c:\Programs\New.txt
set Workfile=c:\Programs\Temp\_workfile_.txt

REM Error if file does not exist
if not exist "%File1%" (
  goto :next_Script
)

REM Remove duplicate lines from the file
  copy NUL "%Workfile%" >NUL
  for /f "tokens=* usebackq" %%B in ("%File1%") do (
    findstr /b /e /c:"%%B" /i "%Workfile%">NUL || echo.%%B>>"%Workfile%"
  )
  copy /y "%Workfile%" "%File1%" >NUL
  if exist "%Workfile%" del "%Workfile%"
)
100questionsAsked:
Who is Participating?
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.

becraigCommented:
easy one liner
gc .\current-file.txt | sort -unique | out-file newfile.txt

Open in new window

0

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
becraigCommented:
Are you doing this for more than one file ?
0
100questionsAuthor Commented:
Actually, I am amalgamating files together, combining that is.. copy *.txt newfile.txt and then I need to remove any duplication within the file itself.  
It needs to check any duplication line by line, comparing lines to lines etc..
0
Hey MSSPs! What's your total cost of ownership?

WEBINAR: Managed security service providers often deploy & manage products from a variety of solution vendors. But is this really the best approach when it comes to saving time AND money? Join us on Aug. 15th to learn how you can improve your total cost of ownership today!

100questionsAuthor Commented:
The script does not work as expected, it's reorganizing all the data into alpha order.  Perhaps I should have made this clearer.  
It need to look at every line and remove any lines which are duplicates, respecting the order of the data which currently exists.
0
100questionsAuthor Commented:
I have posted another question which is much clearer.
0
100questionsAuthor Commented:
This removes duplication of lines, however in the context of what I am looking for it needs to keep one set of data, between a start marker and an end marker as it were.  This does not respect that structure.  I have opened another question which is much more detailed and cleared.
0
becraigCommented:
Great, I will look out for it.

I should be able to make a minor modification and get you to do exactly what you need without changing the sorting of the data.
0
100questionsAuthor Commented:
Thanks for your help.
0
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.